rev version
[lwes-java.git] / src / org / lwes / db / ESFParser.jj
blob9cf835e567f4de106f5a79f47eb376d3cac214c9
1 options {
2   DEBUG_PARSER=false;
3   DEBUG_LOOKAHEAD=false;
4   DEBUG_TOKEN_MANAGER=false;
5   STATIC=false;
8 PARSER_BEGIN(ESFParser)
10 package org.lwes.db;
12 public class ESFParser
14   private String currentEvent;
15   private EventTemplateDB eventTemplateDB;
17   public void setEventTemplateDB(EventTemplateDB DB)
18     { eventTemplateDB = DB; }
20   public EventTemplateDB getEventTemplateDB()
21     { return eventTemplateDB; }
23   public void setCurrentEvent(String evt)
24     { currentEvent = evt; }
26   public String getCurrentEvent()
27     { return currentEvent; }
30 PARSER_END(ESFParser)
32 SKIP :
34   " "
35 | "\t"
36 | "\n"
37 | "\r"
38 | "#" : IN_LINE_COMMENT
41 <IN_LINE_COMMENT> SKIP:
43    "\n" : DEFAULT
44 |  "\r" : DEFAULT
45 |  "\r\n" : DEFAULT
48 <IN_LINE_COMMENT> MORE:
50   < ~[] >
54 TOKEN :
56   < ID: ["a"-"z","A"-"Z","_",":","0"-"9"] (["a"-"z","A"-"Z","_",":","0"-"9"])* >
59 /**
60  * A list of events
61  */
62 void eventlist() :
66   event() ( event() )* <EOF>
69 /**
70  * a single event
71  */
72 void event() :
76   eventName() "{" [ attributeList() ] "}"
79 /**
80  * The name of an event, should be max 256 chars ([a-zA-Z0-9_]*)
81  */
82 void eventName() :
84   Token t;
87   t=<ID>
88   {
89     if ( getEventTemplateDB().addEvent(t.image))
90     {
91       setCurrentEvent(t.image);
92     }
93     else
94     {
95       throw new ParseException("Problem adding event "+t.image);
96     }
97   }
100 void attributeList() :
103   attribute() ( attribute() )*
106 void attribute() :
108   String aType;
109   String anAttribute;
112   aType=type() anAttribute=attributeName() ";" { 
113       if ( !( aType.equals("uint16") 
114             | aType.equals("int16")
115             | aType.equals("uint32")
116             | aType.equals("int32")
117             | aType.equals("string")
118             | aType.equals("ip_addr")
119             | aType.equals("int64")
120             | aType.equals("uint64")
121             | aType.equals("boolean")
122             )
123          ) 
124        {
125          throw new ParseException("No such type '"+aType+"'");
126        }
127       String evt = getCurrentEvent();
128       if ( evt == null ) throw new ParseException("Bad Event");
129       if ( !getEventTemplateDB().addEventAttribute(evt,anAttribute,aType))
130       {
131         throw new ParseException("Problem adding attribute "+evt+"("
132                                  +aType+","+anAttribute+")"); 
133       }
134    }
137 String type() :
139   Token t;
142   t=<ID>
143   {
144     return t.image;
145   }
148 String attributeName() :
150   Token t;
153   t=<ID>
154   {
155     return t.image;
156   }