private Expression Suffix(INode node) { if (node.Name == "quantified") { Debug.Assert(node.Count == 2); var expression = Primary(node[0]); switch (node[1].Name) { case "?": return(OptionalExpression.From(node, expression)); case "*": return(StarExpression.From(node, expression)); case "+": return(PlusExpression.From(node, expression)); default: throw new NotImplementedException(); } } return(Primary(node)); }
private static Expression Expression(INode node) { switch (node.Name) { case "sequence": return(Sequence(node)); case "choice": return(Choice(node)); case "prefix.drop": return(DropExpression.From(node[0], Expression(node[0]))); case "prefix.lift": return(LiftExpression.From(node[0], Expression(node[0]))); case "prefix.fuse": return(FuseExpression.From(node[0], Expression(node[0]))); case "prefix.not": return(NotExpression.From(node[0], Expression(node[0]))); case "suffix.zero-or-more": return(StarExpression.From(node[0], Expression(node[0]))); case "suffix.one-or-more": return(PlusExpression.From(node[0], Expression(node[0]))); case "suffix.zero-or-one": return(OptionalExpression.From(node[0], Expression(node[0]))); case "inline": return(InlineExpression.From(node[0], Tree.Rule.From(Identifier(node[0]), Expression(node[1])))); case "identifier": return(NameExpression.From(node, Identifier(node))); case "any": return(AnyExpression.From(node)); case "verbatim-string": return(StringLiteralExpression.From(node, ((ILeaf)node).Value)); case "character-class": return(Class(node)); case "string": return(String(node)); default: throw new NotImplementedException(); } }