コード例 #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ParseErrorException" /> class.
 /// </summary>
 /// <param name="error">The error message.</param>
 /// <param name="expression">The expression.</param>
 /// <param name="location">The error location.</param>
 /// <param name="innerException">The inner exception.</param>
 public ParseErrorException(string error, string expression, Location location, Exception innerException)
     : base(location.BuildParseError(error, expression), innerException)
 {
     Error = error;
     Expression = expression;
     Location = location.Clone();
 }
コード例 #2
0
        /// <summary>
        ///     Analyzes a specified logical expression and extracts a sequence of tokens.
        /// </summary>
        /// <param name="expression">The logical expression.</param>
        /// <returns>
        ///     A sequence of extracted tokens.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">expression;Expression not provided.</exception>
        public IEnumerable<Token> Analyze(string expression)
        {
            lock (_locker)
            {
                if (expression == null)
                    throw new ArgumentNullException(nameof(expression), "Expression not provided.");

                Location = new Location(line: 1, column: 1);
                Expression = expression;

                var tokens = new List<Token>();
                while (Next())
                {
                    tokens.Add(Token);
                }

                // once we've reached the end of the string, EOF token is returned - thus, parser's lookahead does not have to worry about running out of tokens
                tokens.Add(new Token(TokenType.EOF, string.Empty, new Location(Location)));
                return tokens;
            }
        }
コード例 #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Location" /> class.
 /// </summary>
 /// <param name="location">The location.</param>
 public Location(Location location)
 {
     Line = location.Line;
     Column = location.Column;
 }
コード例 #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ParseErrorException" />.
 /// </summary>
 /// <param name="message">The error message.</param>
 /// <param name="location">The erratic code location.</param>
 public ParseErrorException(string message, Location location)
     : base(message)
 {
     Location = location;
 }
コード例 #5
0
 public void verify_error_message_construction_for_boundary_conditions(Location location, string expression)
 {
     Assert.Equal(
         $@"Parse error on line {location.Line}, last column: error message",
         location.BuildParseError("error message", expression));
 }
コード例 #6
0
 public void verify_error_message_construction(Location location, string indication, string expression)
 {
     Assert.Equal(
         $@"Parse error on line {location.Line}, column {location.Column}:
     ... {indication} ...
     ^--- error message",
         location.BuildParseError("error message", expression));
 }