Whitespace terminators & MakePlusRule in Irony

Sep 3, 2013 at 4:08 PM
(I've already asked this on Stack Overflow - but figured I should share it here too. http://stackoverflow.com/questions/18578267/whitespace-terminators-makeplusrule-in-irony)

I'm trying to create a fairly simple parser using Irony, but am coming to the conclusion that Irony may not be suitable in this particular case.

These is an example of what I'm trying to parse:
server_name  example.com  *.example.com  www.example.*; 

server_name  www.example.com   ~^www\d+\.example\.com$;

server_name   ~^(?<subdomain>.+?)\.(?<domain>.+)$;
I'm using FreeTextLiterals with either a space or semi-colon as a terminator
 var serverNamevalue = new FreeTextLiteral("serverNameValue", FreeTextOptions.None, " ", ";");
I'm then using the MakePlusRule to pick up one or more server_name values:
httpCoreServerName.Rule = "server_name" + httpCoreServerNameItems + semicolon;
httpCoreServerNameItems.Rule = MakePlusRule(httpCoreServerNameItems, serverNamevalue);
However - I think there's a problem with having whitespace as a terminator for the FreeTextLiteral in this case. When I run this, I get a parser error. If I substitute the whitespace for another specific character to act as terminator (and also add this a delimiter in the call to MakePlusRule) - it works fine.

Does anyone have any ideas as to how I could deal with this in Irony?

Mark
Coordinator
Sep 3, 2013 at 7:13 PM
Edited Sep 3, 2013 at 7:14 PM
the problem is with semicolon as terminator. For me, parser got stuck on it producing FreeTextLiteral's with empty content. I've added an option AllowEmpty, so that if it is not set, an empty terminal is not produced. Now it should be working. Here's my test grammar:
  [Language("ServerGrammar", "1", "Http Server name Grammar")]
  public class ServerGrammar : Irony.Parsing.Grammar {
    public ServerGrammar()  : base() {
      var serverNamevalue = new FreeTextLiteral("serverNameValue", FreeTextOptions.None, " ", ";");
      var semicolon = ToTerm(";");
      var httpCoreServerName = new NonTerminal("httpCoreServerName");
      var httpCoreServerNameItems = new NonTerminal("httpCoreServerNameItems");

      httpCoreServerName.Rule = "server_name" + httpCoreServerNameItems + semicolon;
      httpCoreServerNameItems.Rule = MakePlusRule(httpCoreServerNameItems, serverNamevalue);

      this.Root = httpCoreServerName;

    }

  }
your samples work now
Sep 3, 2013 at 8:21 PM
Hi Roman,

Many thanks for adding that change so quickly. I've also tested it out - and it works perfectly.

Keep up the great work on a great project!

Mark.