Skip to content

Commit

Permalink
Make ANTLR 4 grammar more sophisticated
Browse files Browse the repository at this point in the history
Add `:` and `;` symbols to separate argument parts and introduce keys.
  • Loading branch information
enzet committed Aug 20, 2023
1 parent 32a55da commit d4c6635
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions grammar/Moire.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
* Grammar for Moire markup language.
*
* @author Sergey Vartanov
* @since 2 September 2022
* @since 19 August 2023
*/
grammar Moire;

document : markup EOF ;
markup : ( tag | TEXT | WHITESPACE | escapedCharacter | DELIMITER )+ ;
tag : TAG_NAME ( WHITESPACE? argument )* ;
argument : CURLY_OPEN markup CURLY_CLOSE ;
escapedCharacter : BACKSLASH (BACKSLASH | CURLY_OPEN | CURLY_CLOSE) ;
document : markup ;
markup : ( DELIMITER | tag | TEXT | WHITESPACE | escapedCharacter )+ ;
tag : TAG_NAME ( WHITESPACE argument )* ;
argument : CURLY_OPEN argumentElement ( SEMICOLON argumentElement )* CURLY_CLOSE ;
argumentElement : markup | KEY markup ;
escapedCharacter : BACKSLASH (BACKSLASH | CURLY_OPEN | CURLY_CLOSE | COLON | SEMICOLON ) ;

DELIMITER : '\n\n' ;
BACKSLASH : '\\' ;
CURLY_OPEN : '{' ;
CURLY_CLOSE : '}' ;
fragment IDENTIFIER : [A-Za-z0-9_]+;
TAG_NAME: BACKSLASH IDENTIFIER;
WHITESPACE : [ \t\n\r]+;
TEXT : [A-Za-z. \n\t\r]+;
COLON : ':' ;
SEMICOLON : ';' ;
fragment IDENTIFIER : [A-Za-z0-9_]+ ;
TAG_NAME : BACKSLASH IDENTIFIER ;
KEY : IDENTIFIER COLON ;
WHITESPACE : [ \t\n\r]+ ;
TEXT : [A-Za-z. \t\r0-9]+ ;

0 comments on commit d4c6635

Please sign in to comment.