/// <summary> /// Check if <paramref name="identifier"/> is a simple identifier (i.e., token ID) /// </summary> /// <param name="identifier">Tested identifier</param> /// <returns> /// true iff <paramref name="identifier"/> is a simple identifier (it matches the ID token) /// </returns> private static bool IsSimpleIdentifier(string identifier) { // this is not a very nice way to do it but at least we don't have to duplicate // identifier regex in the code var lexer = new QueryLexer(new AntlrInputStream(new StringReader(identifier))); var id = lexer.NextToken().Type; var eof = lexer.NextToken().Type; return(id == QueryLexer.ID && eof == QueryLexer.Eof); }
public void AutoTestCase_Expr_TestPredicateTokenizer8() { Value args = new Value(); args.PushBack(Value.StringValue("expr 'foo and bar'")); QueryLexer tokens = new QueryLexer(args.AsSequence, false); Assert.Equal(QueryLexerTokenKind.TOK_EXPR, tokens.NextToken().Kind); Assert.Equal(QueryLexerTokenKind.TERM, tokens.NextToken().Kind); Assert.Equal(QueryLexerTokenKind.END_REACHED, tokens.NextToken().Kind); }
public void AutoTestCase_Expr_TestPredicateTokenizer1() { Value args = new Value(); args.PushBack(Value.StringValue("foo")); args.PushBack(Value.StringValue("and")); args.PushBack(Value.StringValue("bar")); QueryLexer tokens = new QueryLexer(args.AsSequence); Assert.Equal(QueryLexerTokenKind.TERM, tokens.NextToken().Kind); Assert.Equal(QueryLexerTokenKind.TOK_AND, tokens.NextToken().Kind); Assert.Equal(QueryLexerTokenKind.TERM, tokens.NextToken().Kind); Assert.Equal(QueryLexerTokenKind.END_REACHED, tokens.NextToken().Kind); }
public void AutoTestCase_Expr_TestPredicateTokenizer5() { Value args = new Value(); args.PushBack(Value.StringValue("( foo and")); args.PushBack(Value.StringValue("bar)")); QueryLexer tokens = new QueryLexer(args.AsSequence, false); Assert.AreEqual(QueryLexerTokenKind.LPAREN, tokens.NextToken().Kind); Assert.AreEqual(QueryLexerTokenKind.TERM, tokens.NextToken().Kind); Assert.AreEqual(QueryLexerTokenKind.TOK_AND, tokens.NextToken().Kind); Assert.AreEqual(QueryLexerTokenKind.TERM, tokens.NextToken().Kind); Assert.AreEqual(QueryLexerTokenKind.RPAREN, tokens.NextToken().Kind); Assert.AreEqual(QueryLexerTokenKind.END_REACHED, tokens.NextToken().Kind); }