4 DEBUG_TOKEN_MANAGER=false;
8 PARSER_BEGIN(ESFParser)
12 import org.lwes.util.Log;
14 public class ESFParser
16 private String currentEvent;
17 private EventTemplateDB eventTemplateDB;
19 public void setEventTemplateDB(EventTemplateDB DB)
20 { eventTemplateDB = DB; }
22 public EventTemplateDB getEventTemplateDB()
23 { return eventTemplateDB; }
25 public void setCurrentEvent(String evt)
26 { currentEvent = evt; }
28 public String getCurrentEvent()
29 { return currentEvent; }
40 | "#" : IN_LINE_COMMENT
43 <IN_LINE_COMMENT> SKIP:
50 <IN_LINE_COMMENT> MORE:
62 | < ID: ["a"-"z","A"-"Z","_",":","0"-"9","."] (["a"-"z","A"-"Z","_",":","0"-"9","."])* >
65 | < INTEGER_LITERAL: ["1"-"9"] (["0"-"9"])* >
66 | < STRING_LITERAL: "\""(<ID>)"\"" >
77 event() ( event() )* <EOF>
87 eventName() "{" [ attributeList() ] "}"
91 * The name of an event, should be max 256 chars ([a-zA-Z0-9_]*)
100 if ( getEventTemplateDB().addEvent(t.image))
102 setCurrentEvent(t.image);
106 throw new ParseException("Problem adding event "+t.image);
111 void attributeList() :
114 attribute() ( attribute() )*
124 return Integer.parseInt(t.image);
128 String StringLiteral() :
139 boolean BooleanLiteral() :
153 int IntegerLiteral() :
160 Log.debug("INTEGER LITERAL");
162 return Integer.parseInt(t.image);
163 } catch (NumberFormatException e) {
169 Object defaultValue() :
174 obj = IntegerLiteral()
178 | obj = BooleanLiteral()
182 | obj = StringLiteral()
193 boolean required = false;
194 Object aDefaultValue = null;
197 ((("required" {required = true;} | "optional") (aType=type() anAttribute=attributeName() [ "[" anArraySize = arraySize() "]" ] [ "=" aDefaultValue = defaultValue() ] ";"))
199 (aType=type() anAttribute=attributeName() [ "[" anArraySize = arraySize() "]" ] [ "=" aDefaultValue = defaultValue() ] ";") ) {
200 if ( !( aType.equals("uint16") ||
201 aType.equals("int16") ||
202 aType.equals("uint32") ||
203 aType.equals("int32") ||
204 aType.equals("string") ||
205 aType.equals("ip_addr") ||
206 aType.equals("int64") ||
207 aType.equals("uint64") ||
208 aType.equals("byte") ||
209 aType.equals("boolean")
213 throw new ParseException("No such type '"+aType+"'");
216 String evt = getCurrentEvent();
217 if ( evt == null ) throw new ParseException("Bad Event");
219 if (Log.isLogTrace()) {
220 Log.trace("Type: "+aType+" attr: "+anAttribute+" size: "+anArraySize);
221 Log.trace("Required: "+required);
222 Log.trace("default value: "+aDefaultValue);
225 if (anArraySize > 0) {
229 if ( !getEventTemplateDB().addEventAttribute(evt,
236 throw new ParseException("Problem adding attribute "+evt+"("
237 +aType+","+anAttribute+")");
253 String attributeName() :