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">The name of the token in the outer expression.</param>
        /// <returns>The results of the match.</returns>
        public MatchResult Match(IParseAttempt attempt, string itemName)
        {
            TokenResult tokenResult = attempt.GetToken();
            bool        isMatch     = tokenResult != null && tokenResult.Name == TokenType;
            MatchResult result      = new MatchResult()
            {
                ItemName = itemName,
                IsMatch  = isMatch,
                Context  = tokenResult,
            };

            return(result);
        }
Beispiel #3
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 };
 }
Beispiel #4
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
     });
 }
Beispiel #5
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 #6
0
 /// <summary>
 /// Accepts the attempt as a successful parse, joining the given attempt's tokens
 /// with the current attempt's.
 /// </summary>
 /// <param name="attempt">The child attempt to accept.</param>
 public void Accept(IParseAttempt attempt)
 {
     tokens.AddRange(attempt.Tokens);
 }
Beispiel #7
0
 /// <summary>
 /// Accepts the attempt as a successful parse, joining the given attempt's tokens
 /// with the current attempt's.
 /// </summary>
 /// <param name="attempt">The child attempt to accept.</param>
 public void Accept(IParseAttempt attempt)
 {
     tokens.AddRange(attempt.Tokens);
 }