/// <summary> /// Returns a ParseExpression by processing a suffix token. /// </summary> static object ProcessSuffix(Token token, ParseContext context, object[] args) { var expression = (ParseExpression)token[0].Tag; // Wrap the expression if a quantifier is present if (token.ChildCount > 1) { var quantifier = context.MatchedText(token[1]); if (quantifier.StartsWith("?")) return new Optional(expression); if (quantifier.StartsWith("*")) return new ZeroOrMore(expression); return new OneOrMore(expression); } return expression; }
/// <summary> /// Returns an identifier string by processing an identifier token. /// </summary> static object ProcessIdentifier(Token token, ParseContext context, object[] args) { return context.MatchedText(token[0]); }
/// <summary> /// Returns a PatternTerminal by processing a literal token. /// </summary> static object ProcessRegexLiteral(Token token, ParseContext context, object[] args) { var pattern = context.MatchedText(token[0]); pattern = PatternTerminal.Unescape(pattern); return new PatternTerminal(pattern); }
/// <summary> /// Returns a CustomMatcherTerminal by processing a custom matcher /// literal token. /// </summary> static object ProcessCustomMatcher(Token token, ParseContext context, object[] args) { var matcherName = context.MatchedText(token[0]); matcherName = matcherName.Substring(1, matcherName.Length - 2); return new CustomMatcherTerminal(matcherName); }