0

I'm trying to make a parser in Superpower C# parser library to parse a recursive/chained bracket style accessor. Here is the example of something I want to parse:

indentifier.identifier[exp][exp].identifier[exp]

for the dot accessor I'm using the Parse.Chain and


public enum LangToken
{
    BadToken,
    Identifier,
    ....
    Period,
    ....
}


private static TokenListParser<LangToken, Expression> Identifier { get; } =
            from identifier in Token.EqualTo(LangToken.Identifier)
            select (Expression) new Identifier(identifier);


private static TokenListParser<LangToken, Expression> StaticMemberAccess { get; } =
            from expression in Parse.Chain(Token.EqualTo(LangToken.Period), Identifier, MakeAccess)
            select expression;


private static Expression MakeAccess(LangToken accessor, Expression obj, Expression property)
{
    return new MemberExpression(obj, accessor, property);
}

and this works fine, my guess is that I need to change the Identifier parser and make it a i.e. BracketMemberAccess (btw I don't have this since I don't know how to implement it.. that's my problem to begin with). But my guess ends there. How can I do this?

xDGameStudios
  • 321
  • 1
  • 13
  • can you post your token and parser definitions along with the definitions for `MakeAccess` and `BracketMemberAccess`? also you say it "works fine", so what is the exact issue you're having? – jtate Dec 18 '19 at 16:32
  • The token and parser definitions are the ones used by the Superpower C# library.. that's what I'm using! – xDGameStudios Dec 19 '19 at 09:43
  • what version of Superpower are you using? `LangToken` is not a class or enum in version 2.3.0 which I'm using. Also, `Identifier` is a static class and not a parser on its own. Does your code compile? If so, please add the necessary classes to your question so that it will produce a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). That way, I or someone else can help you. – jtate Dec 19 '19 at 18:34

0 Answers0