Beispiel #1
0
        /// <summary>
        /// Attempts to match the expression item with the values returned by the parser.
        /// </summary>
        /// <param name="attempt">The parser currently iterating over the token source.</param>
        /// <param name="itemName">The name of the item in the outer expression.</param>
        /// <returns>The results of the match.</returns>
        public MatchResult Match(IParseAttempt attempt, string itemName)
        {
            MatchResult result = new MatchResult()
            {
                ItemName = itemName, IsMatch = true
            };

            foreach (ExpressionItem detail in expression.Items)
            {
                IParseAttempt nextAttempt = attempt.Attempt();
                MatchResult   innerResult = detail.Item.Match(nextAttempt, detail.ItemName);
                if (innerResult.IsMatch)
                {
                    attempt.Accept(nextAttempt);
                    result.Matches.Add(innerResult);
                }
                else
                {
                    nextAttempt.Reject();
                    if (detail.IsRequired)
                    {
                        result.IsMatch = false;
                        return(result);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Attempts to match the expression item with the values returned by the parser.
 /// </summary>
 /// <param name="attempt">The parser currently iterating over the token source.</param>
 /// <param name="itemName">This value will be empty for an options list.</param>
 /// <returns>The results of the match.</returns>
 public MatchResult Match(IParseAttempt attempt, string itemName)
 {
     foreach (ExpressionItem option in options)
     {
         IParseAttempt nextAttempt = attempt.Attempt();
         MatchResult   innerResult = option.Item.Match(nextAttempt, option.ItemName);
         if (innerResult.IsMatch)
         {
             attempt.Accept(nextAttempt);
             return(innerResult);
         }
         nextAttempt.Reject();
     }
     return(new MatchResult()
     {
         IsMatch = false
     });
 }