125 lines
4.5 KiB
ANTLR
125 lines
4.5 KiB
ANTLR
/*
|
|
The MIT License (MIT)
|
|
=====================
|
|
|
|
Copyright © 2018 Kevin Matz (kevin@company235.com)
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
obtaining a copy of this software and associated documentation
|
|
files (the “Software”), to deal in the Software without
|
|
restriction, including without limitation the rights to use,
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the
|
|
Software is furnished to do so, subject to the following
|
|
conditions:
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
grammar CommentMacro;
|
|
|
|
/**
|
|
** Parser Rules
|
|
**/
|
|
|
|
prog : statement+ EOF ;
|
|
|
|
statement : macro (':' macro)* NEWLINE?
|
|
| NEWLINE
|
|
;
|
|
|
|
macro
|
|
: op='GM' ( t=target | '*' ) (dev=device)? // Go Master
|
|
| op='GM' ( t=target | '*' ) '/' n=number (dev=device)? // Go Master
|
|
| op='HM' ( t=target | '*' ) (dev=device)? // Halt Master
|
|
| op='AM' ( t=target | '*' ) (dev=device)? // Assert Master
|
|
| op='RM' ( t=target | '*' ) (dev=device)? // Relesae Master
|
|
| op='RA' (dev=device)? // Release All
|
|
| op='RO' (dev=device)? // Release Others
|
|
| op='FM' ( t=target | '*' ) '/' n=number (f=time)? (dev=device)? // Fade Master
|
|
| op='FGM' n=number (f=time)? (dev=device)? // Fade Grand Master
|
|
| op='CM' n=number (dev=device)? // Choose Master
|
|
| op='GL' t=target (dev=device)? // Go List
|
|
| op='GL' t=target '/' n=number (dev=device)? // Go List
|
|
| op='HL' t=target (dev=device)? // Halt List
|
|
| op='AL' t=target (dev=device)? // Assert List
|
|
| op='RL' t=target (dev=device)? // Release List
|
|
| op='GB' t=target (dev=device)? // Go Batch
|
|
| op='HB' t=target (dev=device)? // Halt Batch
|
|
| op='AB' t=target (dev=device)? // Assert Batch
|
|
| op='RB' t=target (dev=device)? // Release Batch
|
|
| op='GS' t=target (dev=device)? // Go Scene
|
|
| op='HS' t=target (dev=device)? // Halt Scene
|
|
| op='AS' t=target (dev=device)? // Assert Scene
|
|
| op='RS' t=target (dev=device)? // Release Scene
|
|
| op='CP' n=number (dev=device)? // Change Page
|
|
| op='CP' d='+' (dev=device)? // Next Page
|
|
| op='CP' d='-' (dev=device)? // Prev Page
|
|
| op='RV' n=number (dev=device)? // Recall View
|
|
| op='RN' dev=device // Reset Node
|
|
| op='GK' t=target (dev=device)? // Go Keystroke Macro
|
|
| op='HK' t=target (dev=device)? // Halt Keystroke Macro
|
|
| op='RK' t=target (dev=device)? // Stop Keystroke Macro
|
|
;
|
|
|
|
time : TIME n=number ;
|
|
device : ntype=nodeType n=number ;
|
|
|
|
nodeType
|
|
: WHOLEHOG
|
|
| DP8K
|
|
| IOP
|
|
;
|
|
|
|
/** recursive targeting is non-greedy */
|
|
target
|
|
: ( number | span ) (',' target)*
|
|
;
|
|
|
|
span
|
|
: n1=number THRU n2=number
|
|
;
|
|
|
|
number : NUMBER ;
|
|
|
|
|
|
/**
|
|
** LEXAR Rules
|
|
**/
|
|
|
|
fragment DIGIT : [0-9] ;
|
|
NUMBER : DIGIT+ ('.' DIGIT+)? ;
|
|
|
|
THRU : '>' ;
|
|
CURRENT : '*' ;
|
|
TIME : 't' ;
|
|
|
|
WHOLEHOG : [hH] ;
|
|
DP8K : [dD] ;
|
|
IOP : 'IOP';
|
|
|
|
NEWLINE : '\r'? '\n' ; // return newlines to parser
|
|
WS : [ \t]+ -> skip ; // ignore whitespace
|
|
|
|
COMMENT // toss c and HTML sytle block comments
|
|
: ( '<!--' .*? '-->'
|
|
| '/*' .*? '*/'
|
|
) -> skip
|
|
;
|
|
|
|
LINE_COMMENT // ignore inline commkents
|
|
: ( '//' ~[\r\n]*
|
|
| '#' ~[\r\n]*
|
|
) -> skip
|
|
;
|