grammar: fix ambiguous string literal lexer part

This commit is contained in:
Peinthor Rene
2013-07-18 15:44:39 +02:00
parent 1bef2501c0
commit e80f445c53
7 changed files with 679 additions and 681 deletions

View File

@@ -1,4 +1,4 @@
/* $ANTLR 2.7.7 (20130425): "sqlite3.g" -> "Sqlite3Lexer.cpp"$ */
/* $ANTLR 2.7.7 (20121001): "sqlite3.g" -> "Sqlite3Lexer.cpp"$ */
#include "Sqlite3Lexer.hpp"
#include <antlr/CharBuffer.hpp>
#include <antlr/TokenStreamException.hpp>
@@ -127,6 +127,14 @@ ANTLR_USE_NAMESPACE(antlr)RefToken Sqlite3Lexer::nextToken()
theRetToken=_returnToken;
break;
}
case 0x22 /* '\"' */ :
case 0x5b /* '[' */ :
case 0x60 /* '`' */ :
{
mQUOTEDID(true);
theRetToken=_returnToken;
break;
}
case 0x2e /* '.' */ :
case 0x30 /* '0' */ :
case 0x31 /* '1' */ :
@@ -159,6 +167,12 @@ ANTLR_USE_NAMESPACE(antlr)RefToken Sqlite3Lexer::nextToken()
theRetToken=_returnToken;
break;
}
case 0x27 /* '\'' */ :
{
mSTRINGLITERAL(true);
theRetToken=_returnToken;
break;
}
case 0x28 /* '(' */ :
{
mLPAREN(true);
@@ -208,18 +222,10 @@ ANTLR_USE_NAMESPACE(antlr)RefToken Sqlite3Lexer::nextToken()
break;
}
default:
if ((_tokenSet_0.member(LA(1))) && ((LA(2) >= 0x0 /* '\0' */ && LA(2) <= 0x7f))) {
mQUOTEDID(true);
theRetToken=_returnToken;
}
else if ((LA(1) == 0x2d /* '-' */ || LA(1) == 0x2f /* '/' */ ) && (LA(2) == 0x2a /* '*' */ || LA(2) == 0x2d /* '-' */ )) {
if ((LA(1) == 0x2d /* '-' */ || LA(1) == 0x2f /* '/' */ ) && (LA(2) == 0x2a /* '*' */ || LA(2) == 0x2d /* '-' */ )) {
mCOMMENT(true);
theRetToken=_returnToken;
}
else if ((LA(1) == 0x27 /* '\'' */ ) && ((LA(2) >= 0x0 /* '\0' */ && LA(2) <= 0x7f))) {
mSTRINGLITERAL(true);
theRetToken=_returnToken;
}
else if ((LA(1) == 0x7c /* '|' */ ) && (LA(2) == 0x7c /* '|' */ )) {
mOROP(true);
theRetToken=_returnToken;
@@ -452,9 +458,9 @@ void Sqlite3Lexer::mQUOTEDID(bool _createToken) {
match('`' /* charlit */ );
{ // ( ... )*
for (;;) {
if ((_tokenSet_1.member(LA(1)))) {
if ((_tokenSet_0.member(LA(1)))) {
{
match(_tokenSet_1);
match(_tokenSet_0);
}
}
else {
@@ -472,9 +478,9 @@ void Sqlite3Lexer::mQUOTEDID(bool _createToken) {
match('[' /* charlit */ );
{ // ( ... )*
for (;;) {
if ((_tokenSet_2.member(LA(1)))) {
if ((_tokenSet_1.member(LA(1)))) {
{
match(_tokenSet_2);
match(_tokenSet_1);
}
}
else {
@@ -492,9 +498,9 @@ void Sqlite3Lexer::mQUOTEDID(bool _createToken) {
match('\"' /* charlit */ );
{ // ( ... )*
for (;;) {
if ((_tokenSet_3.member(LA(1)))) {
if ((_tokenSet_2.member(LA(1)))) {
{
match(_tokenSet_3);
match(_tokenSet_2);
}
}
else {
@@ -507,26 +513,6 @@ void Sqlite3Lexer::mQUOTEDID(bool _createToken) {
match('\"' /* charlit */ );
break;
}
case 0x27 /* '\'' */ :
{
match('\'' /* charlit */ );
{ // ( ... )*
for (;;) {
if ((_tokenSet_4.member(LA(1)))) {
{
match(_tokenSet_4);
}
}
else {
goto _loop19;
}
}
_loop19:;
} // ( ... )*
match('\'' /* charlit */ );
break;
}
default:
{
throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());
@@ -559,18 +545,18 @@ void Sqlite3Lexer::mNUMERIC(bool _createToken) {
case 0x39 /* '9' */ :
{
{ // ( ... )+
int _cnt23=0;
int _cnt20=0;
for (;;) {
if (((LA(1) >= 0x30 /* '0' */ && LA(1) <= 0x39 /* '9' */ ))) {
mDIGIT(false);
}
else {
if ( _cnt23>=1 ) { goto _loop23; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
if ( _cnt20>=1 ) { goto _loop20; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
}
_cnt23++;
_cnt20++;
}
_loop23:;
_loop20:;
} // ( ... )+
{
if ((LA(1) == 0x2e /* '.' */ )) {
@@ -581,11 +567,11 @@ void Sqlite3Lexer::mNUMERIC(bool _createToken) {
mDIGIT(false);
}
else {
goto _loop26;
goto _loop23;
}
}
_loop26:;
_loop23:;
} // ( ... )*
}
else {
@@ -599,18 +585,18 @@ void Sqlite3Lexer::mNUMERIC(bool _createToken) {
match('.' /* charlit */ );
_ttype=DOT;
{ // ( ... )+
int _cnt28=0;
int _cnt25=0;
for (;;) {
if (((LA(1) >= 0x30 /* '0' */ && LA(1) <= 0x39 /* '9' */ ))) {
mDIGIT(false);
}
else {
if ( _cnt28>=1 ) { goto _loop28; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
if ( _cnt25>=1 ) { goto _loop25; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
}
_cnt28++;
_cnt25++;
}
_loop28:;
_loop25:;
} // ( ... )+
break;
}
@@ -655,18 +641,18 @@ void Sqlite3Lexer::mNUMERIC(bool _createToken) {
}
}
{ // ( ... )+
int _cnt32=0;
int _cnt29=0;
for (;;) {
if (((LA(1) >= 0x30 /* '0' */ && LA(1) <= 0x39 /* '9' */ ))) {
mDIGIT(false);
}
else {
if ( _cnt32>=1 ) { goto _loop32; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
if ( _cnt29>=1 ) { goto _loop29; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltForCharException(LA(1), getFilename(), getLine(), getColumn());}
}
_cnt32++;
_cnt29++;
}
_loop32:;
_loop29:;
} // ( ... )+
}
else {
@@ -753,17 +739,17 @@ void Sqlite3Lexer::mCOMMENT(bool _createToken) {
match("--");
{ // ( ... )*
for (;;) {
if ((_tokenSet_5.member(LA(1)))) {
if ((_tokenSet_3.member(LA(1)))) {
{
match(_tokenSet_5);
match(_tokenSet_3);
}
}
else {
goto _loop39;
goto _loop36;
}
}
_loop39:;
_loop36:;
} // ( ... )*
mNL(false);
newline();
@@ -775,10 +761,10 @@ void Sqlite3Lexer::mCOMMENT(bool _createToken) {
{ // ( ... )*
for (;;) {
// nongreedy exit test
if ((LA(1) == 0x2a /* '*' */ ) && (LA(2) == 0x2f /* '/' */ )) goto _loop42;
if ((_tokenSet_5.member(LA(1))) && ((LA(2) >= 0x0 /* '\0' */ && LA(2) <= 0x7f))) {
if ((LA(1) == 0x2a /* '*' */ ) && (LA(2) == 0x2f /* '/' */ )) goto _loop39;
if ((_tokenSet_3.member(LA(1))) && ((LA(2) >= 0x0 /* '\0' */ && LA(2) <= 0x7f))) {
{
match(_tokenSet_5);
match(_tokenSet_3);
}
}
else if ((LA(1) == 0xa /* '\n' */ || LA(1) == 0xd /* '\r' */ )) {
@@ -786,11 +772,11 @@ void Sqlite3Lexer::mCOMMENT(bool _createToken) {
newline();
}
else {
goto _loop42;
goto _loop39;
}
}
_loop42:;
_loop39:;
} // ( ... )*
match("*/");
break;
@@ -867,11 +853,11 @@ void Sqlite3Lexer::mSTRINGLITERAL(bool _createToken) {
}
}
else {
goto _loop48;
goto _loop45;
}
}
_loop48:;
_loop45:;
} // ( ... )*
match('\'' /* charlit */ );
if ( _createToken && _token==ANTLR_USE_NAMESPACE(antlr)nullToken && _ttype!=ANTLR_USE_NAMESPACE(antlr)Token::SKIP ) {
@@ -1149,29 +1135,32 @@ void Sqlite3Lexer::mBITWISERIGHT(bool _createToken) {
}
const unsigned long Sqlite3Lexer::_tokenSet_0_data_[] = { 0UL, 132UL, 134217728UL, 1UL, 0UL, 0UL, 0UL, 0UL };
// \" \' [ `
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_0(_tokenSet_0_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_1_data_[] = { 4294967295UL, 4294967295UL, 4294967295UL, 4294967294UL, 0UL, 0UL, 0UL, 0UL };
const unsigned long Sqlite3Lexer::_tokenSet_0_data_[] = { 4294967295UL, 4294967295UL, 4294967295UL, 4294967294UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10
// 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e
// 0x1f ! \" # $ % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = >
// ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ] ^ _
// a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_1(_tokenSet_1_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_2_data_[] = { 4294967295UL, 4294967295UL, 3758096383UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_0(_tokenSet_0_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_1_data_[] = { 4294967295UL, 4294967295UL, 3758096383UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10
// 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e
// 0x1f ! \" # $ % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = >
// ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ^ _ `
// a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_2(_tokenSet_2_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_3_data_[] = { 4294967295UL, 4294967291UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_1(_tokenSet_1_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_2_data_[] = { 4294967295UL, 4294967291UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10
// 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e
// 0x1f ! # $ % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
// @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ] ^ _ `
// a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_2(_tokenSet_2_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_3_data_[] = { 4294958079UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xb 0xc 0xe 0xf 0x10 0x11 0x12
// 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f !
// \" # $ % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
// C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ] ^ _ ` a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_3(_tokenSet_3_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_4_data_[] = { 4294967295UL, 4294967167UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10
@@ -1180,10 +1169,4 @@ const unsigned long Sqlite3Lexer::_tokenSet_4_data_[] = { 4294967295UL, 42949671
// @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ] ^ _ `
// a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_4(_tokenSet_4_data_,8);
const unsigned long Sqlite3Lexer::_tokenSet_5_data_[] = { 4294958079UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL };
// 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xb 0xc 0xe 0xf 0x10 0x11 0x12
// 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f !
// \" # $ % & \' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B
// C D E F G H I J K L M N O P Q R S T U V W X Y Z [ 0x5c ] ^ _ ` a b c
const ANTLR_USE_NAMESPACE(antlr)BitSet Sqlite3Lexer::_tokenSet_5(_tokenSet_5_data_,8);

View File

@@ -2,7 +2,7 @@
#define INC_Sqlite3Lexer_hpp_
#include <antlr/config.hpp>
/* $ANTLR 2.7.7 (20130425): "sqlite3.g" -> "Sqlite3Lexer.hpp"$ */
/* $ANTLR 2.7.7 (20121001): "sqlite3.g" -> "Sqlite3Lexer.hpp"$ */
#include <antlr/CommonToken.hpp>
#include <antlr/InputBuffer.hpp>
#include <antlr/BitSet.hpp>
@@ -64,8 +64,6 @@ private:
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_3;
static const unsigned long _tokenSet_4_data_[];
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_4;
static const unsigned long _tokenSet_5_data_[];
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_5;
};
#endif /*INC_Sqlite3Lexer_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 (20130425): "sqlite3.g" -> "Sqlite3Parser.hpp"$ */
/* $ANTLR 2.7.7 (20121001): "sqlite3.g" -> "Sqlite3Parser.hpp"$ */
#include <antlr/TokenStream.hpp>
#include <antlr/TokenBuffer.hpp>
#include "sqlite3TokenTypes.hpp"
@@ -125,6 +125,8 @@ private:
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_20;
static const unsigned long _tokenSet_21_data_[];
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_21;
static const unsigned long _tokenSet_22_data_[];
static const ANTLR_USE_NAMESPACE(antlr)BitSet _tokenSet_22;
};
#endif /*INC_Sqlite3Parser_hpp_*/

View File

@@ -92,7 +92,6 @@ QUOTEDID
: '`' ( ~('`') )* '`'
| '[' ( ~(']') )* ']'
| '"' ( ~('"') )* '"'
| '\'' ( ~('\'') )* '\''
;
NUMERIC
@@ -160,7 +159,7 @@ options {
buildAST = true;
}
id : ID | QUOTEDID ;
id : ID | QUOTEDID | STRINGLITERAL ;
databasename
:
@@ -224,7 +223,7 @@ columndef
{#columndef = #([COLUMNDEF, "COLUMNDEF"], #columndef);}
;
name : ID | QUOTEDID;
name : ID | QUOTEDID | STRINGLITERAL;
type_name
:
@@ -339,7 +338,7 @@ suffixexpr
literalvalue
:
NUMERIC
| STRINGLITERAL
// | STRINGLITERAL // captured by columnname
// | blob-literal
| NULL_T
| CURRENT_TIME

View File

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

View File

@@ -1,4 +1,4 @@
// $ANTLR 2.7.7 (20130425): sqlite3.g -> sqlite3TokenTypes.txt$
// $ANTLR 2.7.7 (20121001): sqlite3.g -> sqlite3TokenTypes.txt$
sqlite3 // output token vocab name
ABORT="ABORT"=4
ACTION="ACTION"=5