aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/parser
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/parser')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/parser/lempar.c6
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/parser/sqlite2_parse.cpp6
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/parser/sqlite3_parse.cpp6
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/parser/token.cpp8
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/parser/token.h4
5 files changed, 21 insertions, 9 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/lempar.c b/SQLiteStudio3/coreSQLiteStudio/parser/lempar.c
index 4f9cd5c..2d0e610 100644
--- a/SQLiteStudio3/coreSQLiteStudio/parser/lempar.c
+++ b/SQLiteStudio3/coreSQLiteStudio/parser/lempar.c
@@ -717,7 +717,11 @@ static void yy_reduce(
{
tokens.clear();
const char* fieldName = yyTokenName[yypParser->yystack[i].major];
- if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0))
+
+ // Adding token being subject of this reduction. It's usually not includes in the inherited tokens,
+ // although if inheriting from simple statements, like "FAIL" or "ROLLBACK", this tends to be redundant with the inherited tokens.
+ // That's why we're checking if it's not contained in the inherited tokens and add it only then.
+ if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0) && !yypParser->yystack[i].tokens->contains(yypParser->yystack[i].minor.yy0))
tokens += yypParser->yystack[i].minor.yy0;
tokens += *(yypParser->yystack[i].tokens);
diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/sqlite2_parse.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/sqlite2_parse.cpp
index ffc1fab..81e242d 100644
--- a/SQLiteStudio3/coreSQLiteStudio/parser/sqlite2_parse.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/parser/sqlite2_parse.cpp
@@ -4354,7 +4354,11 @@ static void yy_reduce(
{
tokens.clear();
const char* fieldName = yyTokenName[yypParser->yystack[i].major];
- if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0))
+
+ // Adding token being subject of this reduction. It's usually not includes in the inherited tokens,
+ // although if inheriting from simple statements, like "FAIL" or "ROLLBACK", this tends to be redundant with the inherited tokens.
+ // That's why we're checking if it's not contained in the inherited tokens and add it only then.
+ if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0) && !yypParser->yystack[i].tokens->contains(yypParser->yystack[i].minor.yy0))
tokens += yypParser->yystack[i].minor.yy0;
tokens += *(yypParser->yystack[i].tokens);
diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/sqlite3_parse.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/sqlite3_parse.cpp
index fa8a9d1..9ff6487 100644
--- a/SQLiteStudio3/coreSQLiteStudio/parser/sqlite3_parse.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/parser/sqlite3_parse.cpp
@@ -4973,7 +4973,11 @@ static void yy_reduce(
{
tokens.clear();
const char* fieldName = yyTokenName[yypParser->yystack[i].major];
- if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0))
+
+ // Adding token being subject of this reduction. It's usually not includes in the inherited tokens,
+ // although if inheriting from simple statements, like "FAIL" or "ROLLBACK", this tends to be redundant with the inherited tokens.
+ // That's why we're checking if it's not contained in the inherited tokens and add it only then.
+ if (parserContext->isManagedToken(yypParser->yystack[i].minor.yy0) && !yypParser->yystack[i].tokens->contains(yypParser->yystack[i].minor.yy0))
tokens += yypParser->yystack[i].minor.yy0;
tokens += *(yypParser->yystack[i].tokens);
diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/token.cpp b/SQLiteStudio3/coreSQLiteStudio/parser/token.cpp
index d3e05f1..f2102c3 100644
--- a/SQLiteStudio3/coreSQLiteStudio/parser/token.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/parser/token.cpp
@@ -140,9 +140,9 @@ Range Token::getRange()
return Range(start, end);
}
-bool Token::isWhitespace() const
+bool Token::isWhitespace(bool includeComments) const
{
- return (type == SPACE || type == COMMENT);
+ return (type == SPACE || (includeComments && type == COMMENT));
}
bool Token::isSeparating() const
@@ -490,11 +490,11 @@ TokenList TokenList::filter(Token::Type type) const
return filtered;
}
-TokenList TokenList::filterWhiteSpaces() const
+TokenList TokenList::filterWhiteSpaces(bool includeComments) const
{
TokenList filtered;
foreach (TokenPtr token, *this)
- if (!token->isWhitespace())
+ if (!token->isWhitespace(includeComments))
filtered << token;
return filtered;
diff --git a/SQLiteStudio3/coreSQLiteStudio/parser/token.h b/SQLiteStudio3/coreSQLiteStudio/parser/token.h
index 222ce1a..aecc7ec 100644
--- a/SQLiteStudio3/coreSQLiteStudio/parser/token.h
+++ b/SQLiteStudio3/coreSQLiteStudio/parser/token.h
@@ -190,7 +190,7 @@ struct API_EXPORT Token
*
* Note, that from SQL perspective also comments are whitespaces.
*/
- bool isWhitespace() const;
+ bool isWhitespace(bool includeComments = true) const;
/**
* @brief Tests whether this token represents separating value (like an operator, or parenthesis) in SQL understanding.
@@ -633,7 +633,7 @@ class API_EXPORT TokenList : public QList<TokenPtr>
*
* The condition to test if tokens is a whitespace is a call to Token::isWhitespace().
*/
- TokenList filterWhiteSpaces() const;
+ TokenList filterWhiteSpaces(bool includeComments = true) const;
/**
* @brief Returns sub-list of tokens from this list.