1
0
Fork 0

grammar improvements

This commit is contained in:
Kevin Matz 2018-10-20 13:21:57 -04:00
parent ef40c3e962
commit 7758b76c7d
2 changed files with 59 additions and 66 deletions

View File

@ -1,52 +1,52 @@
grammar CommentMacro;
/** The grammer begins here, as a series of statements. */
prog: statement+ ;
/**
** Parser Rules
**/
/** Each statement has one or many expressions */
statement
: macro NEWLINE
| NEWLINE
;
prog : statement+ EOF ;
statement : macro (':' macro)* NEWLINE
| NEWLINE
;
macro
: 'GM' master device? // Go Master
| 'GM' master SLASH number device? // Go Master
| 'HM' master device? // Halt Master
| 'AM' master device? // Assert Master
| 'RM' master device? // Relesae Master
| 'RA' device? // Release All
| 'RO' device? // Release Others
| 'FM' master SLASH number time? device? // Fade Master
| 'FGM' number time? device? // Fade Grand Master
| 'CM' number device? // Choose Master
| 'GL' target device? // Go List
| 'GL' target SLASH number device? // Go List
| 'HL' target device? // Halt List
| 'AL' target device? // Assert List
| 'RL' target device? // Release List
| 'GB' target device? // Go Batch
| 'HB' target device? // Halt Batch
| 'AB' target device? // Assert Batch
| 'RB' target device? // Release Batch
| 'GS' target device? // Go Scene
| 'HS' target device? // Halt Scene
| 'AS' target device? // Assert Scene
| 'RS' target device? // Release Scene
| 'CP' number device? // Change Page
| 'CP' NEXT device? // Next Page
| 'CP' PREV device? // Prev Page
| 'RV' number device? // Recall View
| 'RN' device // Reset Node
| 'GK' number device? // Go Keystroke Macro
| 'HK' number device? // Halt Keystroke Macro
| 'RK' number device? // Stop Keystroke Macro
: 'GM' master (device)? // Go Master
| 'GM' master SLASH number (device)? // Go Master
| 'HM' master (device)? // Halt Master
| 'AM' master (device)? // Assert Master
| 'RM' master (device)? // Relesae Master
| 'RA' (device)? // Release All
| 'RO' (device)? // Release Others
| 'FM' master SLASH number (time)? (device)? // Fade Master
| 'FGM' number (time)? (device)? // Fade Grand Master
| 'CM' number (device)? // Choose Master
| 'GL' target (device)? // Go List
| 'GL' target SLASH number (device)? // Go List
| 'HL' target (device)? // Halt List
| 'AL' target (device)? // Assert List
| 'RL' target (device)? // Release List
| 'GB' target (device)? // Go Batch
| 'HB' target (device)? // Halt Batch
| 'AB' target (device)? // Assert Batch
| 'RB' target (device)? // Release Batch
| 'GS' target (device)? // Go Scene
| 'HS' target (device)? // Halt Scene
| 'AS' target (device)? // Assert Scene
| 'RS' target (device)? // Release Scene
| 'CP' number (device)? // Change Page
| 'CP' NEXT (device)? // Next Page
| 'CP' PREV (device)? // Prev Page
| 'RV' number (device)? // Recall View
| 'RN' device // Reset Node
| 'GK' number (device)? // Go Keystroke Macro
| 'HK' number (device)? // Halt Keystroke Macro
| 'RK' number (device)? // Stop Keystroke Macro
;
master : (target | CURRENT) ;
time : TIME number ;
device : nodeType number ;
number : NUMBER ;
nodeType
: WHOLEHOG
@ -56,43 +56,36 @@ nodeType
/** recursive targeting is non-greedy */
target
: ( number | span ) also*?
: ( number | span ) (',' target)*
;
span
: number THRU number
;
also
: ALSO target
;
number : NUMBER ;
SLASH : '/' ;
ALSO : ',' ;
THRU : '>' ;
NEXT : '+' ;
PREV : '-' ;
CURRENT : '*' ;
TIME : 't' ;
/**
** LEXAR Rules
**/
SLASH : '/' ;
THRU : '>' ;
NEXT : '+' ;
PREV : '-' ;
CURRENT : '*' ;
TIME : 't' ;
WHOLEHOG : [hH] ;
DP8K : [dD] ;
IOP : 'IOP';
NUMBER // intigers or floats
: [0-9]+ '.' [0-9]*
| '.' [0-9]+
| [0-9]+
;
fragment DIGIT : [0-9] ;
NUMBER : DIGIT+ ('.' DIGIT+)? ;
NEWLINE // return newlines to parser (end-statement signal)
: '\r'? '\n'
;
WS // ignore whitespace
: [ \t]+
-> skip
;
NEWLINE : '\r'? '\n' ; // return newlines to parser
WS : [ \t]+ -> skip ; // ignore whitespace
COMMENT // toss c and HTML sytle block comments
: ( '<!--' .*? '-->'
@ -100,7 +93,7 @@ COMMENT // toss c and HTML sytle block comments
) -> skip
;
LINE_COMMENT
LINE_COMMENT // ignore inline commkents
: ( '//' ~[\r\n]*
| '#' ~[\r\n]*
) -> skip

View File

@ -17,7 +17,7 @@ You must also install the ANTLR tool. On a mac with homebrew, do:
Clone this repository and building the lexer and parser for Python3
> $ antlr4 -Dlanguage=Python3 CommentMacro.g4
> $ antlr -Dlanguage=Python3 CommentMacro.g4
@ -46,6 +46,6 @@ These Comment Macros do not have supporting equivelents in OSC:
Pleas feel welcome to submit pull requests or patches that enable support for:
* Sending target ranges as batches
* Multiple comment macros per line
* More than one comment macros per line
* Send multi-macro line as a batch
* Timing on master fades