5 class BookkeepingLexer extends Lexer;
9 k=10; // needed for newline junk
10 //charVocabulary='\u0000'..'\u007F'; // allow ascii
11 exportVocab=BookkeepingLexer;
15 LEFT_PAREN: '(' { System.out.println("LEFT PARENTHESIS '('"); };
16 RIGHT_PAREN: ')' { System.out.println("RIGHT PARENTHESIS ')'"); };
18 System.out.println("DELIMITER ','");
19 System.out.println( "" );
20 System.out.println( "" );
25 OPT_ENTRY: "-entry" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )* { System.out.println("-entry"); };
26 OPT_ACCOUNT: "-account" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
27 OPT_JOURNAL: "-journal" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
28 OPT_NAME: "-name" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
29 OPT_TYPE: "-type" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
30 OPT_CWEIGHT: "-counterWeight" WS("debit"|"credit");
31 OPT_AMOUNT: "-amount" WS(('0'..'9')+'.'('0'..'9')('0'..'9'))*;
32 OPT_ID: "-id" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
33 OPT_ENTRYNUM: "-entrynum" WS('0'..'9')*;
34 OPT_DATE: "-date" WS(('0'..'9')('0'..'9')'/'('0'..'9')('0'..'9')'/'('0'..'9')('0'..'9')('0'..'9')('0'..'9'))*;
35 OPT_FILE: "-F" WS( 'A'..'Z' | 'a'..'z' | '0'..'9' )*;
39 COMMAND_CREATE: ("create")+ { System.out.println("COMMAND_CREATE"); };
40 COMMAND_ADD!: ("add")+ { System.out.println("COMMAND_ADD"); };
41 COMMAND_REMOVE: ("remove")+ { System.out.println("COMMAND_REMOVE"); };
42 COMMAND_REVERSE: ("reverse")+ { System.out.println("COMMAND_REVERSE"); };
43 COMMAND_FIND: ("find")+ { System.out.println("COMMAND_FIND"); };
44 COMMAND_LOAD: ("load")+ { System.out.println("COMMAND_LOAD"); };
45 COMMAND_LIST: ("list")+ { System.out.println("COMMAND_LIST"); };
46 COMMAND_LOGIN: ("login")+ { System.out.println("COMMAND_LOGIN"); };
47 COMMAND_LOGOUT: ("logout")+ { System.out.println("COMMAND_LOGOUT"); };
48 COMMAND_EXIT: ("exit")+ { System.out.println("COMMAND_EXIT"); };
53 END_COMMAND: ';' { System.out.println("END COMMAND ';'"); };
54 /*WHITESPACE: ( ' ' | '\r' | '\n' | '\t' ) {
55 System.out.println("");
56 System.out.println("WHITE SPACE ' '");
67 "<!DOCTYPE" WS rootElementName:NAME
68 { System.out.println("ROOTELEMENT: "+rootElementName.getText()); }
71 ( "SYSTEM" WS sys1:STRING
72 { System.out.println("SYSTEM: "+sys1.getText()); }
74 | "PUBLIC" WS pub:STRING WS sys2:STRING
75 { System.out.println("PUBLIC: "+pub.getText()); }
76 { System.out.println("SYSTEM: "+sys2.getText()); }
80 ( dtd:INTERNAL_DTD ( WS )?
81 { System.out.println("DTD: "+dtd.getText()); }
87 protected INTERNAL_DTD
90 // reports warning, but is absolutely ok (checked generated code)
91 // besides this warning was not generated with k=1 which is
92 // enough for this rule...
93 ( options {greedy=true;} : NL
94 | STRING // handle string specially to avoid to mistake ']' in string for end dtd
103 // { AttributesImpl attributes = new AttributesImpl(); }
107 ( ATTR /*[attributes]*/ ( WS )? )*
109 if (target.getText().equalsIgnoreCase("xml")) {
110 // this is the xml declaration, handle it
111 System.out.println("XMLDECL: "+target.getText());
113 System.out.println("PI: "+target.getText());
122 : "<!--" c:COMMENT_DATA "-->"
123 { System.out.println("COMMENT: "+c.getText()); }
126 protected COMMENT_DATA
128 //( options {greedy=true;} : NL
131 ( options {greedy=true;} : WS | NAME | CHAR )*
137 "</" g:NAME ( WS )? '>'
138 { System.out.println("ENDTAG: "+g.getText()); }
149 protected STARTTAG_VS_EMPTYTAG
152 ( "/>" { $setType(EMPTYTAG); System.out.println("EMTYTAG"); }
154 '>' { $setType(STARTTAG); System.out.println("STARTTAG"); }
157 protected STARTCHUNK! :
158 // XX should org.xml.sax.AttributesImpl be replaced by something else?
159 // { AttributesImpl attributes = new AttributesImpl(); }
166 { System.out.println("STARTCHUNK: "+g.getText()); } ;
169 /* Right now, not so necessary to determine that element will contain 'parsed'
173 { System.out.println("PCDATA: "+p.getText()); }
176 protected PCDATA_DATA
178 ( options {greedy=true;} : NL
179 //| ~( '<' | '\n' | '\r' )
185 : "<![CDATA[" p:CDATA_DATA "]]>"
186 { System.out.println("CDATABLOCK: "+p.getText()); }
191 ( options {greedy=true;} : NL
196 protected ATTR // [AttributesImpl attributes]
197 : name:NAME ( WS )? '=' ( WS )? value:STRING_NO_QUOTE
199 { attributes.addAttribute("", "", name.getText(), "CDATA",
203 { System.out.println("ATTRIBUTE: "+name.getText()+"="+value.getText()); }
206 protected STRING_NO_QUOTE
208 | '\''! (~'\'')* '\''!
217 : ( LETTER | '_' | ':') ( options {greedy=true;} : NAMECHAR )*
221 : LETTER | DIGIT | '.' | '-' | '_' | ':'
233 protected CHAR: ( options {greedy=true;}
234 : '/' | '<' | '>' | '\'' | "\"" | '.' | '-' | '_' | ':'
240 protected WS: ( options{ greedy=true; } : ' ' | '\r' | '\n' | '\t' )+
242 //System.out.println("");
243 //System.out.println("WHITE SPACE ' '");
244 $setType(Token.SKIP);
255 { System.out.println("WHITESPACE"); }
267 // Alexander Hinds & Terence Parr
268 // from antlr 2.5.0: example/html
270 // '\r' '\n' can be matched in one alternative or by matching
271 // '\r' in one iteration and '\n' in another. I am trying to
272 // handle any flavor of newline that comes in, but the language
273 // that allows both "\r\n" and "\r" and "\n" to all be valid
274 // newline is ambiguous. Consequently, the resulting grammar
275 // must be ambiguous. I'm shutting this warning off.
278 generateAmbigWarnings=false;
293 ( tag:STARTTAG_VS_EMPTYTAG
294 ( WS | PI | COMMENT | CDATABLOCK )*
297 { System.out.println(" TOKEN LITERAL ["+ tag.getText() +"]"); }
299 (tag2:STARTTAG_VS_EMPTYTAG)
300 { System.out.println(" TOKEN LITERAL ["+ tag2.getText() +"]"); }
302 //(delim:',') { $setType(DELIMITER); }
306 System.out.println("");