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?