grammar: Fix parsing of complex expression

This fixes parsing of expressions of the form '(x) AND/OR y' and similar
types. It also fixes expression of the '(x)' type and of the '(x op y
AND z op w)' type.

See issue #1454.
This commit is contained in:
Martin Kleusberg
2018-07-10 23:07:38 +02:00
parent 961141ec36
commit 788134eee6
7 changed files with 671 additions and 603 deletions

View File

@@ -1,4 +1,4 @@
/* $ANTLR 2.7.7 (20160127): "sqlite3.g" -> "Sqlite3Lexer.cpp"$ */
/* $ANTLR 2.7.7 (20171109): "sqlite3.g" -> "Sqlite3Lexer.cpp"$ */
#include "Sqlite3Lexer.hpp"
#include <antlr/CharBuffer.hpp>
#include <antlr/TokenStreamException.hpp>

View File

@@ -2,7 +2,7 @@
#define INC_Sqlite3Lexer_hpp_
#include <antlr/config.hpp>
/* $ANTLR 2.7.7 (20160127): "sqlite3.g" -> "Sqlite3Lexer.hpp"$ */
/* $ANTLR 2.7.7 (20171109): "sqlite3.g" -> "Sqlite3Lexer.hpp"$ */
#include <antlr/CommonToken.hpp>
#include <antlr/InputBuffer.hpp>
#include <antlr/BitSet.hpp>

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
#define INC_Sqlite3Parser_hpp_
#include <antlr/config.hpp>
/* $ANTLR 2.7.7 (20160127): "sqlite3.g" -> "Sqlite3Parser.hpp"$ */
/* $ANTLR 2.7.7 (20171109): "sqlite3.g" -> "Sqlite3Parser.hpp"$ */
#include <antlr/TokenStream.hpp>
#include <antlr/TokenBuffer.hpp>
#include "sqlite3TokenTypes.hpp"

View File

@@ -431,7 +431,8 @@ functionname
expr
:
( LPAREN subexpr (COMMA subexpr)+ RPAREN binaryoperator LPAREN subexpr (COMMA subexpr)+ RPAREN )
( LPAREN expr RPAREN ((AND | OR) expr)* )
| ( LPAREN subexpr (COMMA subexpr)+ RPAREN binaryoperator LPAREN subexpr (COMMA subexpr)+ RPAREN )
| ( subexpr ((binaryoperator | AND | OR) subexpr )* )
;

View File

@@ -1,7 +1,7 @@
#ifndef INC_sqlite3TokenTypes_hpp_
#define INC_sqlite3TokenTypes_hpp_
/* $ANTLR 2.7.7 (20160127): "sqlite3.g" -> "sqlite3TokenTypes.hpp"$ */
/* $ANTLR 2.7.7 (20171109): "sqlite3.g" -> "sqlite3TokenTypes.hpp"$ */
#ifndef CUSTOM_API
# define CUSTOM_API

View File

@@ -945,7 +945,10 @@ TablePtr CreateTableWalker::table()
if(num_paren == 0)
break;
expr.append(textAST(tc));
if(tc->getType() == sqlite3TokenTypes::AND || tc->getType() == sqlite3TokenTypes::OR)
expr.append(" " + textAST(tc) + " ");
else
expr.append(textAST(tc));
tc = tc->getNextSibling();
}