feat(package): hemar: antlr grammar, but still does not work
This commit is contained in:
49
package/hemar/grammar/antlr/HemarLexer.g4
Normal file
49
package/hemar/grammar/antlr/HemarLexer.g4
Normal file
@@ -0,0 +1,49 @@
|
||||
lexer grammar HemarLexer;
|
||||
|
||||
// ---------- default mode: plain text ----------
|
||||
|
||||
// Everything that is not the start of "{[" is TEXT
|
||||
TEXT
|
||||
: ( ~'{' | '{' ~'[' )+
|
||||
;
|
||||
|
||||
// When we see "{[", emit LeftBrace and enter TAG mode
|
||||
LeftBrace
|
||||
: '{[' -> pushMode(TAG)
|
||||
;
|
||||
|
||||
// skip whitespace in plain text if you want
|
||||
SKIP_WS
|
||||
: [ \t\r\n]+ -> skip
|
||||
;
|
||||
|
||||
// ---------- TAG mode: inside {[ ... ]} ----------
|
||||
|
||||
mode TAG;
|
||||
|
||||
fragment WS: [ \t\r\n] ;
|
||||
|
||||
For : 'for';
|
||||
In : 'in';
|
||||
End : 'end';
|
||||
|
||||
// identifier inside tag
|
||||
Path
|
||||
: String
|
||||
| String '.' Path
|
||||
;
|
||||
|
||||
String
|
||||
: ( ~[.\] \t\r\n] | ']' ~[}. \t\r\n] )+
|
||||
| '"' ( ~'"' | '\\' '"' )+ '"'
|
||||
;
|
||||
|
||||
// closing "]}": emit RightBrace and go back to default mode
|
||||
RightBrace
|
||||
: ']}' -> popMode
|
||||
;
|
||||
|
||||
// skip whitespace inside tag
|
||||
SKIP_TAG_WS
|
||||
: WS+ -> skip
|
||||
;
|
||||
Reference in New Issue
Block a user