Extended grammar to recognize more tokens
This commit is contained in:
parent
acc6aa2681
commit
8830040d1b
@ -87,51 +87,71 @@ whileStatement
|
||||
;
|
||||
|
||||
anyToken
|
||||
: ANY
|
||||
: ABSTRACT
|
||||
| ANY
|
||||
| ARROWOPERATOR
|
||||
| ASSIGNMENTOPERATOR
|
||||
| BAREMODULE
|
||||
| BEGIN
|
||||
| BITSHIFTOPERATOR
|
||||
| BITSTYPE
|
||||
| BREAK
|
||||
| CATCH
|
||||
| CCALL
|
||||
| CHAR
|
||||
| CONST
|
||||
| CONTINUE
|
||||
| DO
|
||||
| ELSE
|
||||
| ELSIF
|
||||
| END
|
||||
| EXPORT
|
||||
| EXTERNALCOMMAND
|
||||
| FINALLY
|
||||
| FOR
|
||||
| FUNCTION
|
||||
| GLOBAL
|
||||
| IDENTIFIER
|
||||
| IF
|
||||
| IMMUTABLE
|
||||
| IMPORT
|
||||
| IMPORTALL
|
||||
| INSTANCEOF
|
||||
| LET
|
||||
| LOCAL
|
||||
| MACRO
|
||||
| MODULE
|
||||
| NUMERICAL
|
||||
| PIPEOPERATOR
|
||||
| QUOTE
|
||||
| RETURN
|
||||
| STAGED_FUNCTION
|
||||
| STRING
|
||||
| STRUCT
|
||||
| TRY
|
||||
| TYPE
|
||||
| TYPEALIAS
|
||||
| USING
|
||||
| WHERE
|
||||
| WHILE
|
||||
| '(' anyToken*? ')'
|
||||
| '[' anyToken*? ']'
|
||||
| '{' anyToken*? '}'
|
||||
| '='
|
||||
| '=>'
|
||||
| '&&' // short-circuit
|
||||
| '||' // short-circuit
|
||||
| '==' // to disambiguate from "="
|
||||
| '>='
|
||||
| '<='
|
||||
| '<'
|
||||
| '<:'
|
||||
| '>'
|
||||
| '...'
|
||||
;
|
||||
|
||||
// Lexer
|
||||
|
||||
|
||||
fragment
|
||||
Digit
|
||||
: [0-9]
|
||||
;
|
||||
|
||||
INT
|
||||
: Digit+
|
||||
;
|
||||
|
||||
FLOAT : Digit+ '.' Digit* ;
|
||||
|
||||
COMMENTS : '#' (~[=\r\n]~[\r\n]*)? -> skip; // skip #= because otherwise multiline comments are not recognized, see next line
|
||||
MULTILINECOMMENTS1 : '#=' .*? '=#' -> skip;
|
||||
MULTILINECOMMENTS2 : '```' .*? '```' -> skip;
|
||||
@ -139,28 +159,112 @@ MULTILINESTRING : '"""' ('\\"'|.)*? '"""' -> skip;
|
||||
NL : '\r'? '\n' -> skip ;
|
||||
WHITESPACE : [ \t]+ -> skip ;
|
||||
|
||||
ABSTRACT : 'abstract' ;
|
||||
|
||||
ARROWOPERATOR
|
||||
: '--'
|
||||
| '-->'
|
||||
;
|
||||
|
||||
ASSIGNMENTOPERATOR
|
||||
: ':=' | '+=' | '-=' | '*=' | '/=' | '//=' | './/='
|
||||
| '.*=' | './=' | '\\=' | '.\\=' | '^=' | '.^=' | '%=' | '.%='
|
||||
| '|=' | '&=' | '$=' | '=>' | '<<=' | '>>=' | '>>>='
|
||||
| '.+=' | '.-='
|
||||
;
|
||||
|
||||
BAREMODULE : 'baremodule' ;
|
||||
BEGIN : 'begin' ;
|
||||
BITSHIFTOPERATOR : '<<' | '>>' | '>>>' | '.<<' | '.>>' | '.>>>';
|
||||
BITSTYPE : 'bitstype' ;
|
||||
BREAK : 'break' ;
|
||||
CATCH : 'catch' ;
|
||||
CCALL : 'ccall' ;
|
||||
CHAR : '\'' '\\'? .? '\'' ;
|
||||
CONST : 'const' ;
|
||||
CONTINUE : 'continue' ;
|
||||
DO : 'do' ;
|
||||
ELSE : 'else' ;
|
||||
ELSIF : 'elsif' ;
|
||||
END : 'end' ;
|
||||
EXPORT : 'export' ;
|
||||
EXTERNALCOMMAND : '`' .*? '`' ;
|
||||
FINALLY : 'finally' ;
|
||||
FOR : 'for' ;
|
||||
FUNCTION : 'function' ;
|
||||
GLOBAL : 'global' ;
|
||||
IF : 'if' ;
|
||||
IMMUTABLE : 'immutable' ;
|
||||
IMPORT : 'import' ;
|
||||
IMPORTALL : 'importall' ;
|
||||
INSTANCEOF : '::' ;
|
||||
LET : 'let' ;
|
||||
LOCAL : 'local' ;
|
||||
MACRO : 'macro' ;
|
||||
STRING : '"' ('\\\\'|'\\"'|'$(' ('$(' .*? ')'|'"' .*? '"'|.)*? ')'|.)*? '"';
|
||||
MODULE : 'module' ;
|
||||
PIPEOPERATOR : '|>'| '<|' ;
|
||||
QUOTE : 'quote' ;
|
||||
RETURN : 'return' ;
|
||||
STAGEDFUNCTION : 'stagedfunction' ;
|
||||
STRING : '"' ('\\\\'|'\\"'|'$(' ('$(' .*? ')'|'"' .*? '"'|.)*? ')'|.)*? '"' ;
|
||||
STRUCT : 'struct' ;
|
||||
TRY : 'try' ;
|
||||
TYPE : 'type' ;
|
||||
TYPEALIAS : 'typealias' ;
|
||||
USING : 'using' ;
|
||||
WHERE : 'where' ;
|
||||
WHILE : 'while' ;
|
||||
INSTANCE_OF : '::';
|
||||
|
||||
IDENTIFIER : [$a-zA-Z_] [a-zA-Z_0-9]* ;
|
||||
NUMERICAL
|
||||
: INT_LITERAL
|
||||
| BINARY
|
||||
| OCTAL
|
||||
| HEX
|
||||
| FLOAT32_LITERAL
|
||||
| FLOAT64_LITERAL
|
||||
| HEX_FLOAT
|
||||
;
|
||||
|
||||
ANY : . ;
|
||||
INT_LITERAL : DEC_DGT+;
|
||||
BINARY : '0b'BIN_DGT+;
|
||||
OCTAL : '0o'OCT_DGT+;
|
||||
HEX : '0x'HEX_DGT+;
|
||||
|
||||
FLOAT32_LITERAL
|
||||
: DEC_DGT+ '.'? DEC_DGT* EXP32?
|
||||
| '.' DEC_DGT* EXP32?
|
||||
;
|
||||
|
||||
FLOAT64_LITERAL
|
||||
: DEC_DGT+ '.'? DEC_DGT* EXP64?
|
||||
| '.' DEC_DGT* EXP64?
|
||||
;
|
||||
|
||||
HEX_FLOAT : '0x' HEX_DGT? ('.' HEX_DGT*)? ( 'p' | 'P' ) ( '+' | '-' )? DEC_DGT+;
|
||||
|
||||
fragment EXP32 : [f] [+\-]? DEC_DGT+;
|
||||
fragment EXP64 : [e] [+\-]? DEC_DGT+;
|
||||
|
||||
IDENTIFIER : ('_'|UNi) ('_'|UNi|DEC_DGT)* '!'?;
|
||||
fragment DEC_DGT : [0-9_];
|
||||
fragment BIN_DGT : [0-1_];
|
||||
fragment OCT_DGT : [0-7_];
|
||||
fragment HEX_DGT : [0-9A-Fa-f_];
|
||||
|
||||
fragment UNi
|
||||
: 'A'..'Z'
|
||||
| 'a'..'z'
|
||||
| '\u00C0'..'\u00D6'
|
||||
| '\u00D8'..'\u00F6'
|
||||
| '\u00F8'..'\u02FF'
|
||||
| '\u0370'..'\u037D'
|
||||
| '\u037F'..'\u1FFF'
|
||||
| '\u200C'..'\u200D'
|
||||
| '\u2070'..'\u218F'
|
||||
| '\u2C00'..'\u2FEF'
|
||||
| '\u3001'..'\uD7FF'
|
||||
| '\uF900'..'\uFDCF'
|
||||
| '\uFDF0'..'\uFFFD'
|
||||
;
|
||||
|
||||
ANY : . ;
|
Loading…
x
Reference in New Issue
Block a user