问题描述:

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?

网友答案:

Have you checked his Python sample?

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

相关阅读:
Top