FreeTextLiteral

Jan 18, 2012 at 9:55 AM

Hello,

I have following grammar:

public class TestGrammar : Grammar
    {
        public TestGrammar()
        {
            FreeTextLiteral freeTextLiteral = new FreeTextLiteral("freeTextLiteral", ";");

            NonTerminal mainNonTerminal = new NonTerminal("mainNonTerminal", typeof(TestAstNode));
            mainNonTerminal.Rule = "VAR" + freeTextLiteral;

            this.Root = mainNonTerminal;
        }
    }

For testing I use following code:

TestGrammar testGrammar = new TestGrammar();
Parser parser2 = new Parser(testGrammar);
ParseTree parseTree2 = parser2.Parse("VARtest;");

I dont know why but Root of ParseTree is NULL. Can you please help me how to obtain valid result? I am not sure how FreeTextLiteral exactly works.

Thank you.

Coordinator
Jan 23, 2012 at 12:53 AM

Using "var" as a term in the grammar, as you use it, requires that in the source text it is followed by a space or some delimiter - only in this case parser would recognize it as a term "Var". What you need is specify "Var" as freeTextLiteral prefix - just add it to freeTextLiteral.Firsts set.

roman