Created
August 22, 2014 15:03
-
-
Save 166MMX/22e5d8a35c08fcb73214 to your computer and use it in GitHub Desktop.
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 zconf; | |
options { | |
language=Java; | |
} | |
tokens { | |
T_OR = '||' ; | |
T_AND = '&&' ; | |
T_EQUAL = '=' ; | |
T_UNEQUAL = '!=' ; | |
T_NOT = '!' ; | |
T_LPAREN = '(' ; | |
T_RPAREN = ')' ; | |
T_DQUOT = '"' ; | |
T_SQUOT = '\'' ; | |
} | |
// input | |
// statement | |
// block | |
// option | |
// entry | |
// | |
input : start | |
; | |
start : EOL* | |
mainMenuStatement? | |
statementList* | |
; | |
statementList | |
: commonStatement | |
| entryStatement | |
| EOL | |
; | |
commonStatement | |
: ifStatement | |
| sourceStatement | |
; | |
entryStatement | |
: entry | |
; | |
// T_LPAREN > T_NOT > T_EQUAL, T_UNEQUAL > T_AND > T_OR | |
// T_OR < T_AND < T_EQUAL, T_UNEQUAL < T_NOT < T_LPAREN | |
expr | |
: left=or_expr | |
; | |
or_expr | |
: left=and_expr | |
( T_OR right=or_expr | |
)? | |
; | |
and_expr | |
: left=comp_expr | |
( T_AND right=and_expr | |
)? | |
; | |
comp_expr | |
: left=not_expr | |
( T_EQUAL right=not_expr | |
| T_UNEQUAL right=not_expr | |
)? | |
; | |
not_expr | |
: left=list_expr | |
| T_NOT right=not_expr | |
; | |
list_expr | |
: left=symbol | |
| T_LPAREN right=or_expr T_RPAREN | |
; | |
symbol | |
: CONST | |
| STRING | |
; | |
entry | |
: configEntry | |
| menuConfigEntry | |
| choiceEntry | |
| commentEntry | |
| menuEntry | |
; | |
configEntry | |
: 'config' symbol EOL | |
configAttributeStatement+ | |
; | |
menuConfigEntry | |
: 'menuconfig' symbol EOL | |
configAttributeStatement+ | |
; | |
choiceEntry | |
: 'choice' symbol? EOL | |
choiceAttributeStatement+ | |
choiceBlock* | |
'endchoice' EOL | |
; | |
choiceBlock | |
: ifStatement | |
| commentEntry | |
| configEntry | |
| menuConfigEntry | |
| sourceStatement | |
; | |
commentEntry | |
: 'comment' promptValue EOL | |
commentAttributeStatement+ | |
; | |
menuEntry | |
: 'menu' promptValue EOL | |
menuAttributeStatement+ | |
menuBlock | |
'endmenu' EOL | |
; | |
menuBlock | |
: ifStatement | |
| commentEntry | |
| configEntry | |
| menuConfigEntry | |
| sourceStatement | |
| menuEntry | |
| choiceEntry | |
; | |
ifStatement | |
: 'if' expr EOL | |
ifBlock* | |
'endif' EOL | |
; | |
ifBlock | |
: ifStatement | |
| commentEntry | |
| configEntry | |
| menuConfigEntry | |
| sourceStatement | |
| menuEntry | |
| choiceEntry | |
; | |
sourceStatement | |
: 'source' promptValue EOL | |
; | |
mainMenuStatement | |
: 'mainmenu' promptValue EOL | |
; | |
configAttributeStatement | |
: configAttribute EOL | |
; | |
choiceAttributeStatement | |
: choiceAttribute EOL | |
; | |
commentAttributeStatement | |
: commentAttribute EOL | |
; | |
menuAttributeStatement | |
: menuAttribute EOL | |
; | |
configAttribute | |
: typeEntryAttribute | |
| promptEntryAttribute | |
| defaultEntryAttribute | |
| typeAndDefaultEntryAttribute | |
| forwardDependencyEntryAttribute | |
| reverseDependencyEntryAttribute | |
| visibileEntryAttribute | |
| rangeEntryAttribute | |
| helpEntryAttribute | |
| optionEntryAttribute | |
; | |
choiceAttribute | |
: typeEntryAttribute | |
| promptEntryAttribute | |
| defaultEntryAttribute | |
| typeAndDefaultEntryAttribute | |
| forwardDependencyEntryAttribute | |
| reverseDependencyEntryAttribute | |
| visibileEntryAttribute | |
| rangeEntryAttribute | |
| helpEntryAttribute | |
| optionEntryAttribute | |
| optionalEntryAttribute | |
; | |
commentAttribute | |
: forwardDependencyEntryAttribute | |
| reverseDependencyEntryAttribute | |
; | |
menuAttribute | |
: forwardDependencyEntryAttribute | |
| reverseDependencyEntryAttribute | |
| visibileEntryAttribute | |
; | |
typeEntryAttribute | |
: ('bool' | 'tristate' | 'string' | 'hex' | 'int') promptValue? | |
; | |
promptEntryAttribute | |
: 'prompt' promptValue ifCondition? | |
; | |
defaultEntryAttribute | |
: 'default' expr ifCondition? | |
; | |
typeAndDefaultEntryAttribute | |
: ('def_bool' | 'def_tristate') expr ifCondition? | |
; | |
forwardDependencyEntryAttribute | |
: 'depends' 'on' expr | |
; | |
reverseDependencyEntryAttribute | |
: 'select' symbol ifCondition? | |
; | |
visibileEntryAttribute | |
: 'visible' ifCondition | |
; | |
rangeEntryAttribute | |
: 'range' symbol symbol ifCondition? | |
; | |
helpEntryAttribute | |
: 'help' | |
; | |
optionEntryAttribute | |
: 'option' 'defconfig_list' 'modules' 'env' '=' 'allnoconfig_y' | |
; | |
optionalEntryAttribute | |
: 'optional' | |
; | |
promptValue | |
: symbol; | |
ifCondition | |
: 'if' expr; | |
DASHES | |
: '---' {$channel=HIDDEN;} | |
; | |
COMMENT | |
: '#' ~('\r'|'\n')* EOL {$channel=HIDDEN;} | |
; | |
WS : (' '|'\t') {$channel=HIDDEN;} | |
; | |
EOL : '\r'? '\n' | |
; | |
CONST | |
: ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-'|'/'|'.')+ | |
; | |
STRING | |
: '"' ( ESC_SEQ | ~('\\'| '"') )* '"' | |
| '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\'' | |
; | |
fragment HEX_DIGIT | |
: ('0'..'9'|'a'..'f'|'A'..'F') | |
; | |
fragment ESC_SEQ | |
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | |
| UNICODE_ESC | |
| HEX_ESC | |
| OCTAL_ESC | |
; | |
fragment OCTAL_ESC | |
: '\\' ('0'..'3') ('0'..'7') ('0'..'7') | |
| '\\' ('0'..'7') ('0'..'7') | |
| '\\' ('0'..'7') | |
; | |
fragment HEX_ESC | |
: '\\' 'x' HEX_DIGIT HEX_DIGIT | |
; | |
fragment UNICODE_ESC | |
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment