示例#1
0
 /// <summary>
 /// Parses the the specified expression into a
 /// <see cref="BooleanExpression"/>.
 /// </summary>
 /// <param name="expression">An expression.</param>
 /// <returns>A <see cref="BooleanExpression"/>
 /// object that is the root of the parse tree.</returns>
 public BooleanExpression Parse(string expression)
 {
     this.lexer = new LexicalAnalyzer(expression);
     this.MoveNext();
     BooleanExpression c = this.ParseOrOperator();
     this.AssertTokenType(TokenType.EndOfFile);
     return c;
 }
示例#2
0
        /// <summary>
        /// Parses the the specified expression into a
        /// <see cref="BooleanExpression"/>.
        /// </summary>
        /// <param name="expression">An expression.</param>
        /// <returns>A <see cref="BooleanExpression"/>
        /// object that is the root of the parse tree.</returns>
        public BooleanExpression Parse(string expression)
        {
            this.lexer = new LexicalAnalyzer(expression);
            this.MoveNext();
            BooleanExpression c = this.ParseOrOperator();

            this.AssertTokenType(TokenType.EndOfFile);
            return(c);
        }
示例#3
0
        private void HighlightTokens()
        {
            this.SelectionStart = 0;
            this.SelectionLength = this.Text.Length;

            this.SelectionUnderlineColor = UnderlineColor.None;
            this.SelectionUnderlineStyle = UnderlineStyle.None;

            LexicalAnalyzer lexer = new LexicalAnalyzer(this.Text);

            TokenType lastToken = TokenType.Any;

            for (TokenType tokenType = lexer.MoveNext(); tokenType != TokenType.EndOfFile; tokenType = lexer.MoveNext())
            {
                this.SelectionStart = lexer.CurrentMatch.Index;
                this.SelectionLength = lexer.CurrentMatch.Length;

                switch (tokenType)
                {
                    case TokenType.And:
                    case TokenType.Or:
                    case TokenType.Not:
                        this.SelectionColor = Color.Blue;
                        break;
                    case TokenType.Identity:
                    case TokenType.Role:
                        this.SelectionColor = Color.Navy;
                        break;
                    case TokenType.Word:
                    case TokenType.QuotedString:
                        if (lastToken == TokenType.Identity || lastToken == TokenType.Role)
                        {
                            this.SelectionColor = Color.Navy;
                        }
                        else
                        {
                            this.SelectionColor = Color.Black;
                        }
                        break;
                    default:
                        this.SelectionColor = Color.Black;
                        break;
                }

                lastToken = tokenType;
            }
        }