header{ package joji.rsys; } class DefLexer extends Lexer; options { exportVocab = DefLexer; testLiterals=false; // don't automatically test for literals k=3; charVocabulary='\u0003'..'\uFFFE'; } tokens { "if"; TK_ELIF="elif"; TK_ELSE="else"; "fi"; TK_THEN="then"; TK_EXIT; "true"; "false"; "begin"; "end"; "A"; "address"; "alarm"; "allow"; "among"; "anonymous"; "answer"; "ask"; "association"; "at"; "attendance"; "attendant"; "audio"; "B"; "base"; "before"; "binary"; "bottom"; "button"; "by"; "camera"; "channel"; "channels"; "choice"; "classwork"; "codec"; "color"; "connect"; "connection"; "control"; "controller"; "count"; "cycle"; "date" ; "debug"; "default"; "define"; "desk"; "dhcp"; "dio"; "dir"; "direct"; "discard"; "drive"; "driver"; "enquete"; "ether"; "exist"; "exit"; "file"; "filename"; "first"; "fixed"; "flicker"; "font"; "frame"; "gap"; "graph"; "group"; "height"; "horizontal"; "host"; "icon"; "id"; "initial"; "input"; "int"; "interval"; "label"; "layout"; "left"; "length"; "level"; "list"; "location"; "log"; "loop"; "menu"; "mixer"; "monitor"; "move"; "multiple"; "my"; "navigation"; "not"; "ntsc"; "number"; "on"; "only"; "origin"; "out"; "output"; "panel"; "pc"; "plus"; "port"; "position"; "presentor"; "projector"; "question"; "rgb"; "real"; "receive"; "record"; "remote"; "request"; "restore"; "right"; "room"; "save"; "select"; "selected"; "selection"; "selector"; "self"; "send"; "sensor"; "show"; "shutdown"; "size"; "skip"; "space"; "speaking"; "special"; "start"; "stop"; "student"; "style"; "switch"; "system"; "table"; "terminal"; "terminate"; "test"; "text"; "time"; "title"; "top"; "tracking"; "unsaved"; "var"; "video"; "voice"; "wakeonlan"; "width"; "window"; "with"; "zoom"; } { public void uponEOF() throws TokenStreamException, CharStreamException { Def.includeEof(); } public void reportError(RecognitionException ex) { DefElm.semanticError = true; super.reportError(ex); } } AND : '&' ; COLON : ':' ; COMMA : ',' ; EQ : '=' ; EQUAL : "==" ; LARROW : "<-" ; LPAR : '(' ; MINUS : '-' ; NOT : '!' ; NOTEQ : "!=" ; PLUS : '+' ; RARROW : "->" ; RPAR : ')' ; SEMI : ';' ; SLASH : '/' ; STAR : '*' ; ESC : '\\' ( 'n' { $setText("\n"); } | 'r' { $setText("\r"); } | 't' { $setText("\t"); } | '"' { $setText("\""); } | '\\' { $setText("\\"); } ) ; WS : ( ' ' | '\t' )+ { $setType(Token.SKIP); } ; NEWLINE : ( "\r\n" | '\r' | '\n' ) { newline(); $setType(Token.SKIP);} ; INT : ('0'..'9')+ ; MINT : '-' ('0'..'9')+ ; HEX : '0' ('x' | 'X') ('0'..'9' | 'A'..'F' | 'a'..'f')+ { String v = $getText; $setText(v.substring(2)); } ; MHEX : '-' '0' ('x' | 'X') ('0'..'9' | 'A'..'F' | 'a'..'f')+ { String v = $getText; $setText(v.substring(3)); } ; STR : '"'! (ESC|~('"'|'\\'))* '"'! ; VAR options { testLiterals=true; } : ('A'..'Z' | 'a'..'z' | '_') ( 'A'..'Z' | 'a'..'z' | '_' | '0'..'9' )* ; COMMENT : "%" (~('\n'|'\r'))* { $setType(Token.SKIP); } ; TRANSPARENT : "#(" { Def.transparent(); $setType(Token.SKIP); } ; TRANSPARENT_CLOSE : ")#" ; INC_OPEN { String path="", s=""; } : "#<" (WS)? ( t1:STR { if(Def.isOk()) { path = t1.getText(); }} | t2:VAR { if(Def.isOk()) { s = t2.getText(); path = DefElm.getVarStr(s); }} ) ( options { generateAmbigWarnings=false; } : ( WS ( '+' (WS)? )? | '+' (WS)? ) ( t4:STR { if(Def.isOk()) { s = t4.getText(); path = path.concat(s); }} | t5:VAR { if(Def.isOk()) { s = t5.getText(); s = DefElm.getVarStr(s); path = path.concat(s); }} ) )* (WS)? ( ">?" { if(Def.isOk()) {Def.include(path, true); }} | '>' { if(Def.isOk()) {Def.include(path, false); }} ) { $setType(Token.SKIP); } ; GUARD { int i2=1; DefElmVar v1=null, v4=null; boolean ok=false; DefElm v=null; } : "#[" (WS)? t1:VAR (WS)? { if(Def.isOk()){ v1 = DefElm.getVariable(t1.getText()); }} ( { if(Def.isOk()){ if(v1 != null) ok = v1.getBoolean(); }} | EQUAL (WS)? ( t2:INT { if(Def.isOk()){ if(v1 != null){ i2 = (new Integer(t2.getText())).intValue(); ok = v1.getInt() == i2; } }} | t3:STR { if(Def.isOk()){ if(v1 != null){ ok = v1.getString().equals(t3.getText()); } }} | t4:VAR { if(Def.isOk()){ v4 = DefElm.getVariable(t4.getText()); if(v4 != null) v = v4.getElm(); if((v1 != null) && (v != null)){ ok = v.equals(v1); } }} ) (WS)? ) (NOT { ok = !ok; } )? '?' { if(!ok){ loop: while(true){ char c1=LA(1); switch(c1){ case EOF_CHAR: break loop; case ']': char c2=LA(2); if(c2=='#'){ match(c1); match(c2); if(Def.guardLevel == 0) break loop; Def.guardLevel--; }else{ match(c1); } break; case '#': c2=LA(2); if(c2=='['){ match(c1); match(c2); Def.guardLevel++; }else{ match(c1); } break; case '\n': match(c1); newline(); break; default: match(c1); break; } } } } { $setType(Token.SKIP); } ; GUARD_END : "]#" { $setType(Token.SKIP); } ;