Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative paths are not evaluated #39

Open
IgneButene opened this issue Dec 2, 2020 · 1 comment
Open

Alternative paths are not evaluated #39

IgneButene opened this issue Dec 2, 2020 · 1 comment

Comments

@IgneButene
Copy link

IgneButene commented Dec 2, 2020

I am trying to parse this simple string: "test internal procedure" using the grammar below.
I get an error saying parser is expecting "var". It doesn't make any sense because this string perfectly fits the MethodDeclaration rule. If I uncomment the below MemberAttribute.Q(), which is placed inside GlobalVarSection rule, it all works. But it's an empty rule, it shouldn't change anything, but it does. Looks like when rules start the same way, Irony does not fall back to check the alternative path.

`
using Irony.Parsing;
using System;
using System.Collections.Generic;
using System.Text;

namespace Parser
{

[Language("AL")]
class ALGrammarTest : Grammar
{
    public ALGrammarTest()
    {
        var Member = new NonTerminal("Member");
        var GlobalVarSection = new NonTerminal("GlobalVarSection");
        var MethodDeclaration = new NonTerminal("MethodDeclaration");
        var MemberAttribute = new NonTerminal("MemberAttribute");

        var AccessModifier = ToTerm("internal");
        var VarKeyword = ToTerm("var");
        var ProcedureKeyword = ToTerm("procedure");

        Member.Rule =
              GlobalVarSection
              | MethodDeclaration;

        GlobalVarSection.Rule =
            /*MemberAttribute.Q()
            + */
            "test"
            + AccessModifier.Q()
            + VarKeyword;

        MethodDeclaration.Rule =
              MemberAttribute.Q()
              + "test"
              + AccessModifier.Q()
              + ProcedureKeyword;

        MemberAttribute.Rule = Empty;

        // Root
        this.Root = Member;
    }
}

`

@rivantsov
Copy link
Contributor

  1. Do not use Q() method, it is deprecated
  2. As far as I could guess, you are trying to parse before validating the grammar. Did you try loading it in Grammar Explorer? Load it there and see if there are any conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants