Class ClaferLexer
java.lang.Object
org.clafer.frontend.ClaferLexer
Splits a model in the full Clafer language into tokens, as the compiler's
lexer does (
clafer.cf, generated by BNFC and Alex).
The rules are the compiler's, and so is the longest match:
- a name starts with a letter, and goes on with letters, digits,
_and'; a reserved word, e.g.,someorX, is aTokenKind.KEYWORD. A letter is an ASCII letter or a Latin-1 letter,Àtoÿwithout×and÷; - a number is an integer, a real with digits on both sides of the point,
or a double, a real with an exponent (
1.5e-3); - a string has the escapes
\" \\ \n \t, and may span lines; - comments (
//to the end of the line,/* */) and escapes ([alloy| |],[choco| |]) are set aside, with their spans.
U+00FF is an error anywhere, in a string or a comment too.
A column counts characters, and a tab moves to the next column after a
multiple of 8, as in the compiler's messages.
The lexer does not stop at an error, as the compiler's does: an unexpected character is reported and skipped, and an unterminated string or comment is reported and ends the input.
-
Nested Class Summary
Nested Classes -
Method Summary
-
Method Details
-
lex
Splits a model into tokens.- Parameters:
source- the text of the model- Returns:
- the tokens, the comments and escapes, and the errors
-