Last active
February 8, 2019 10:52
-
-
Save mentiflectax/7978ee79047986906195980bf7bdd9ca to your computer and use it in GitHub Desktop.
WFT Grammar starting point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar wft; | |
@header { | |
} | |
@lexer::header { | |
} | |
@members { | |
} | |
wftFile: | |
{ | |
System.out.println("Heyo!"); | |
} | |
(CommentLine | assignment | NewLine)* | |
itemTypeDefinition | |
EOF | |
; | |
/** | |
* ItemTypeDefinition | |
* DEFINE ITEM_TYPE | |
* END ITEM_TYPE | |
*/ | |
itemTypeDefinition: | |
'DEFINE ITEM_TYPE' NewLine | |
(KeyName|TransStmt|BaseStmt|NewLine)+ | |
WhiteSpace* 'DEFINE ITEM_ATTRIBUTE' NewLine | |
(KeyName|TransStmt|BaseStmt)* | |
WhiteSpace* 'END ITEM_ATTRIBUTE' NewLine | |
'END ITEM_TYPE' | |
; | |
/** | |
* KeyName | |
* KEY NAME VARCHAR2(8) | |
*/ | |
KeyName: WhiteSpace* KeyNameStart .* {$channel = HIDDEN;} NewLine; | |
fragment KeyNameStart: 'KEY NAME VARCHAR2('; | |
/** | |
* TransStmt | |
* TRANS DISPLAY_NAME VARCHAR2(80) | |
*/ | |
TransStmt: WhiteSpace* TransStmtStart .* {$channel = HIDDEN;} NewLine; | |
fragment TransStmtStart: 'TRANS'; | |
/** | |
* BaseStmt | |
BASE PROTECT_LEVEL NUMBER | |
*/ | |
BaseStmt: WhiteSpace* BaseStmtStart .* {$channel = HIDDEN;} NewLine; | |
fragment BaseStmtStart: 'BASE'; | |
/** | |
* Assignment | |
*/ | |
assignment: | |
{ | |
System.out.println("Assignment found!"); | |
} | |
target=AssignmentTarget | |
WhiteSpace '=' WhiteSpace | |
value=String { | |
} | |
NewLine; | |
AssignmentTarget: A (A|D|'_')*; | |
String: '"' ~'"'* '"' | |
; | |
/** | |
* Comment | |
*/ | |
CommentLine: CommentStart .* {$channel = HIDDEN;} NewLine; | |
fragment CommentStart: '#'; | |
// Lexer rules | |
fragment D: '0'..'9'; | |
fragment A: 'A'..'Z' | |
| 'a'..'z'; | |
StringLength: D+; | |
NewLine : '\r' '\n' | '\n' | '\r'; | |
WhiteSpace: ' '; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment