Xbase comes with a small set of lexer rules, which can be overridden and hence changed by users. However the default implementation is carefully chosen and it is recommended to stick with the lexical syntax described in the following.
Identifiers are used to name all constructs, such as types, methods and variables. Xbase uses the default Identifier-Syntax from Xtext - compared to Java, they are slightly simplified to match the common cases while having less ambiguities. They start with a letter a-z, A-Z or an underscore followed by more of these characters or a digit 0-9.
Identifiers may not have the same spelling as any reserved keyword. However, identifiers starting with a ^ are so called escaped identifiers. Escaped identifiers are used in cases when there is a conflict with a reserved keyword. Imagine you have introduced a keyword service in your language but want to call a Java property service at some point. In such cases you use an escaped identifier ^service to reference the Java property.
terminal ID: '^'? ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ;
String literals can either use single quotes (') or double quotes (") as their terminals. When using double quotes all literals allowed by Java string literals are supported. In addition new line characters are allowed, that is in Xbase all string literals can span multiple lines. When using single quotes the only difference is that single quotes within the literal have to be escaped and double quotes do not.
In contrast to Java, equal string literals within the same class do not neccessarily refer to the same instance at runtime.
//TODO
" the quick brown fox jumps over the lazy dog."
Integer literals consist of one or more digits. Only decimal literals are supported and they always result in a value of type java.lang.Integer (it might result in native type int when translated to Java, see Types). The compiler makes sure that only numbers between 0 and Integer.MAX (0x7fffffff) are used.
There is no negative integer literal, instead the expression -23 is parsed as the prefix operator - applied to an integer literal.
terminal INT returns ecore::EInt: ('0'..'9')+ ;
Xbase comes with two different kinds of comments: Single-line comments and multi-line comments. The syntax is the same as the one known from Java (see § 3.7 Comments).
terminal ML_COMMENT : '/*' -> '*/' ; terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')? ;
The white space characters ' ', '\t', '\n', and '\r are allowed to occur anywhere between the other syntactic elements.
The following list of words are reserved keywords, thus reducing the set of possible identifiers:
However, in case some of the keywords have to be used as identifiers, the escape character for identifiers comes in handy.