126 lines
4.1 KiB
ANTLR
126 lines
4.1 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
|
|
: 'GM' ( target | '*' ) device? #MasterGo
|
|
| 'GM' ( target | '*' ) '/' number device? #MasterGoto
|
|
| 'HM' ( target | '*' ) device? #MasterHalt
|
|
| 'AM' ( target | '*' ) device? #MasterAssert
|
|
| 'RM' ( target | '*' ) device? #MasterRelease
|
|
| 'RA' device? #ReleaseAll
|
|
| 'RO' device? #ReleaseOthers
|
|
| 'FM' ( target | '*' ) '/' number time? device? #MasterFade
|
|
| 'FGM' number time? device? #FadeGrandMaster
|
|
| 'CM' number device? #MasterChoose
|
|
| 'GL' target device? #ListGo
|
|
| 'GL' target '/' number device? #ListGoto
|
|
| 'HL' target device? #ListHalt
|
|
| 'AL' target device? #ListAssert
|
|
| 'RL' target device? #ListRelese
|
|
| 'GB' target device? #BatchGo
|
|
| 'HB' target device? #BatchHalt
|
|
| 'AB' target device? #BatchAssert
|
|
| 'RB' target device? #BatchRelease
|
|
| 'GS' target device? #SceneGo
|
|
| 'HS' target device? #SceneHalt
|
|
| 'AS' target device? #SceneAssert
|
|
| 'RS' target device? #SceneRelease
|
|
| 'CP' number device? #PageChange
|
|
| 'CP' '+' device? #PageNext
|
|
| 'CP' '-' device? #PagePrev
|
|
| 'RV' number device? #RecallView
|
|
| 'RN' device #NodeReset
|
|
| 'GK' target device? #MacroGo
|
|
| 'HK' target device? #MacroHalt
|
|
| 'RK' target device? #MacroStop
|
|
| 'INT' number device? #SelectIntensity
|
|
| 'POS' number device? #SelectPosition
|
|
| 'COLR' number device? #SelectColour
|
|
| 'BEAM' number device? #SelectBeam
|
|
| 'WAIT' number #Wait
|
|
| 'PASS' #Pass
|
|
;
|
|
|
|
time : TIME number ;
|
|
device : nodeType 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 // ignore inline commkents
|
|
: ( '//' ~[\r\n]*
|
|
| '#' ~[\r\n]*
|
|
) -> skip
|
|
;
|