grammar g;
// %doc(file = "idocfile.yml")
prog: (decl | expr)+
;
decl: VAR '=' '"' STR '"'
|'%doc' '(' VAR '=' '"' STR '"' ')'
|'%quiz' '(' VAR '=' '"' STR '"' ')' .*? '%quiz'
;
expr:expr '*' expr
|expr '+' expr
|expr '-' expr
|expr '=' expr
|DOC
|STR
;
// tokens
VAR: [a-zA-Z0-9_]+ ;
STR: [a-zA-Z.]*;
WS: [ \t\n]+ -> skip;
Testing example:
%doc(file = "idocfile.yml")
%quiz(title= "assembler quiz")
test
%quiz
For this testing this example with the above grammar the antlr shows error:
line 2:14 mismatched input 'assembler' expecting STR
line 2:24 mismatched input 'quiz' expecting '='
line 2:28 missing '=' at '"'
line 2:29 mismatched input ')' expecting STR
line 2:36 mismatched input '%quiz' expecting '='
line 4:0 mismatched input '<EOF>' expecting '('