Extending Xbase
In this section, we will extend the Xbase Expressions DSL presented in the previous chapter with a new Xbase expression. We will add the new XExpression
eval to the DSL, which takes as an argument any Xbase expression.
In order to present the aspects of Xbase that need to be customized when adding new expressions, we want our new EvalExpression
to have the following semantics:
- It can be used both as a statement and as an expression inside any other expression
- It has a
String
type and the argument expression must not have typevoid
- When it is used as a statement, it will be compiled into a Java
System.out.println
statement with the evaluation of the argument expression - When it is used inside another expression, it will be compiled into a Java
String
expression corresponding to the string representation of the evaluated argument expression.
Note
This semantics does not necessarily make sense, but it allows us to explore many aspects of the customization of Xbase.