The project provides an expression language built using Xtext and a runtime engine to evaluate the expressions. The expression grammar can be imported in other Xtext DSLs to create composable and reusable languages using Xtext. It can also be used to evaluate expressions independently. Currently, the runtime is in Java language but it can be updated to any other language as well.
DSL Developers who need to run expressions in their DSL can import the Common-Xtext-Expression-Language and the ready-to-use runtime engine in the DSL.
- Add the maven dependency
<groupId>com.intuit.dsl.expression</groupId>
<artifactId>com.intuit.dsl.expression.runtime</artifactId>
<version>${latest}</version>
- Code usage
DataValue value = ExpressionRuntime.newExpressionRuntime()
.withExpressionContent(expressionString)
.evaluate();
#Example
let’s say you are creating a new DSL for representing a rule engine. Something like below:
Rules myRules {
when ${expression} then rule1
when ${expression} then rule2
when ${expression} then rule3
}
You can import the expression language to represent the ${expression} in your DSL and execute the available expressions from the Common-Xtext-Expression-Language.
- Java 8
- Maven 3
- Clone common-xtext-expression-language
- Run
mvn clean install
- Import the runtime module
com.intuit.dsl.expression.runtime
. This is standard java project which can be imported in your favorite editor.
-
Install Xtext SDK in Eclipse:
a. In Eclipse, click Help --> Install New Software.
b. In Available Software, click Add to add a repository with the following location http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/
c. Select the repository just added in 'Work with' dropdown.
d. Select and install Xtext Complete SDK. -
Restart Eclipse.
-
Edit the grammar
-
Right click on GenerateExpression.mwe2. Run As --> 1 MWE2 Workflow.
OR
mvn clean install
inside the project
You should be able to use the grammar changes in your runtime.
Read the Contribution guide