GIGen language

The GIGen pattern file grammar looks like (you can refer to the GrammerIntelliForJs.grm file in source control for complete spec.
  1. Each statement is separated by semi-colon.
  2. If a line starts with '+' then it means the pattern definition following it is a public pattern.
  3. if a line does not start with '+' then the pattern is treated as private pattern.
  4. All public pattern will appear in the final GIMachine code generation (JavaScript as of now) as 'OR' i.e. your machine will support any of the public pattern.
  5. A single GIMachine can have multiple public pattern
  6. A pattern can be re-used in another pattern by $PatternName<captureName> where PatternName should have been defined before & CaptureName is the tagName you want to give for text matching against the pattern

Examples:

  • 1. Writing GIGen file to support query "get customer info <CustomerName>

PersonName = "[a-zA-Z]+";
+ CustomerQuery = show info for $PersonName<CustomerName>;


PersonName is a private pattern. CustomerQuery is public ('+' - remember ?) and uses PersonName ...but when personName AS CustomerName.

Copy the above code into a text file & use the GIGen tool to generate JavaScript, a sample implementation is here.
  • 2. Writing GIGen file support query "show invoice from <StartDate> to <EndDate>"

Date = "\d\d/\d\d/\d\d\d\d";
+ InvoiceQuery = show invoice from $Date<StartDate> to $Date<EndDate>;

Note that we are using the Date pattern twice - for StartDate and EndDate.

Last edited Jan 15, 2011 at 7:57 AM by rb_adhikari, version 5

Comments

No comments yet.