1

I am trying to parse a very naive indentation-sensitive language with only two constructs (hello the statement, and fun a block definition).

hello
hello
fun
  hello
  hello
hello

In order to do that, I have composed the following grammar with Irony:

public class NaiveIndent : Grammar
{
    public NaiveIndent()
        : base(true) // CaseSensitive
    {
        var myexp = ToTerm("hello");
        var fun = ToTerm("fun");

        var statementList = new NonTerminal("statementList");
        var statement = new NonTerminal("statement");
        var block = new NonTerminal("block");

        statementList.Rule = MakePlusRule(statementList, NewLineStar, statement);
        statement.Rule = (myexp | block) + NewLine;
        block.Rule = fun + NewLine + Indent + statementList + Dedent;

        Root = statementList;
        LanguageFlags = LanguageFlags.NewLineBeforeEOF;
    }
}

Yet parsing the sample fails with the error (4,3) Syntax error, expected: INDENT

Could anyone pinpoint what I am doing wrong?

Joannes Vermorel
  • 8,976
  • 12
  • 64
  • 104

1 Answers1

0

Have you checked his Python sample?

http://irony.codeplex.com/SourceControl/latest#Irony.Samples/MiniPython/MiniPython.cs

Den
  • 1,827
  • 3
  • 25
  • 46