X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/9f94b672a5dc32da5ad01742bd4e976315a30d9c..c6ad2948bb98d42f8e0883ef82cd14cd2d5eda60:/antlr4-cpp-runtime-4.9.2-source/demo/TLexer.g4 diff --git a/antlr4-cpp-runtime-4.9.2-source/demo/TLexer.g4 b/antlr4-cpp-runtime-4.9.2-source/demo/TLexer.g4 new file mode 100644 index 0000000..ac2128c --- /dev/null +++ b/antlr4-cpp-runtime-4.9.2-source/demo/TLexer.g4 @@ -0,0 +1,86 @@ +lexer grammar TLexer; + +// These are all supported lexer sections: + +// Lexer file header. Appears at the top of h + cpp files. Use e.g. for copyrights. +@lexer::header {/* lexer header section */} + +// Appears before any #include in h + cpp files. +@lexer::preinclude {/* lexer precinclude section */} + +// Follows directly after the standard #includes in h + cpp files. +@lexer::postinclude { +/* lexer postinclude section */ +#ifndef _WIN32 +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif +} + +// Directly preceds the lexer class declaration in the h file (e.g. for additional types etc.). +@lexer::context {/* lexer context section */} + +// Appears in the public part of the lexer in the h file. +@lexer::members {/* public lexer declarations section */ +bool canTestFoo() { return true; } +bool isItFoo() { return true; } +bool isItBar() { return true; } + +void myFooLexerAction() { /* do something*/ }; +void myBarLexerAction() { /* do something*/ }; +} + +// Appears in the private part of the lexer in the h file. +@lexer::declarations {/* private lexer declarations/members section */} + +// Appears in line with the other class member definitions in the cpp file. +@lexer::definitions {/* lexer definitions section */} + +channels { CommentsChannel, DirectiveChannel } + +tokens { + DUMMY +} + +Return: 'return'; +Continue: 'continue'; + +INT: Digit+; +Digit: [0-9]; + +ID: LETTER (LETTER | '0'..'9')*; +fragment LETTER : [a-zA-Z\u0080-\u{10FFFF}]; + +LessThan: '<'; +GreaterThan: '>'; +Equal: '='; +And: 'and'; + +Colon: ':'; +Semicolon: ';'; +Plus: '+'; +Minus: '-'; +Star: '*'; +OpenPar: '('; +ClosePar: ')'; +OpenCurly: '{' -> pushMode(Mode1); +CloseCurly: '}' -> popMode; +QuestionMark: '?'; +Comma: ',' -> skip; +Dollar: '$' -> more, mode(Mode1); +Ampersand: '&' -> type(DUMMY); + +String: '"' .*? '"'; +Foo: {canTestFoo()}? 'foo' {isItFoo()}? { myFooLexerAction(); }; +Bar: 'bar' {isItBar()}? { myBarLexerAction(); }; +Any: Foo Dot Bar? DotDot Baz; + +Comment : '#' ~[\r\n]* '\r'? '\n' -> channel(CommentsChannel); +WS: [ \t\r\n]+ -> channel(99); + +fragment Baz: 'Baz'; + +mode Mode1; +Dot: '.'; + +mode Mode2; +DotDot: '..';