GIGen Tool (GIGen.exe) is a .Net application (you'll need .Net 2.0 atleast) that helps you generate the Javascript code for a pattern grammar. It has its own mini language.


well, its very simple, if you have written the pattern specification in a text file (I prefer giving the .gijs extension) then use GIGen.exe as:

>GIGen.exe source-file-path /L <language-code> /O <output-file-path> /M machine-name

If you don't provide the /M machine-name then a default name of "oMachine" is assumed.

Example: >GIGen c:\temp\simpleCustomerQuery.gijs /O C:\temp\simpleCustomerQOutput.js /M oGIMachine


For a complete work, you'll need:
  1. Write a pattern file based on GIGen mini language
  2. Use GIGen.exe to generate JavaScript file against the pattern file you wrote
  3. Download & Include the GrammarIntelliForJS.js file from my site or download it from the source repository. I recommend taking it from source repository, that way you get the latest one.
  4. Include the generated JavaScript file in your html/web-page

In the page were you want the intellisense, you need to handle the onKeyUp event and call upon the GImachine's Suggestions method. Here's a sample code:

            var arrSuggestions = oGIMachine.Suggestions(sText); // sText is the text entered by user so far, oGIMachine is the value you gave to /M parameter in GIGen tool

            if (arrSuggestions != null && arrSuggestions.length > 0) {
                for (i = 0; i < arrSuggestions.length; i++) {      // In this case we just construct a html & display the suggestion in a div control
                    if (arrSuggestions[i].IsLiteral) {
                        sHTML += "<b>L:</b> &nbsp;" + arrSuggestions[i].Pattern + "<br>";                       // if you have some other UI element for suggestions display, your JavaScript will change
                    } else {
                        sHTML += "<b>R:</b> &nbsp;" + arrSuggestions[i].Pattern + "  [" + arrSuggestions[i].Name + "]<br>";
                oDiv.innerHTML = sHTML;
            } else {
                oDiv.innerHTML = ""; // No suggestions... may be incorrect sentence or end of query

When you want to parse the input to capture the relevant data, use code similar to below. Here I'm capturing the customerName.

                var oMatchCollection = oGIMachine.ProcessText(sText); // sText is user entered data
                if (oMatchCollection != null) {
                var sCustomerName = "";
                oTrace.value = oMatchCollection.ToXML();  // In case you want to see what the response looks like ...

                // Now, its time to get the result ... lets capture the "CustomerName" that user entered
                sCustomerName = oMatchCollection.NamedMatches["CustomerName"].Value;
                // At this point you can do whatever you want with the data ... we'r just displaying it off.
                oDiv.innerHTML = "Result: Captured customerName = '<b>" + sCustomerName + "'</b>";
            } else {
                oTrace.value = "No matches...";

More examples at Quick Start Tutorial.

Last edited Jan 15, 2011 at 7:33 AM by rb_adhikari, version 9


No comments yet.