Skip to content

Commit

Permalink
fix(grammar): Avoid ambiguity between "/" as the division operator an…
Browse files Browse the repository at this point in the history
…d "/" as a SQL*Plus command

Example:

"select * from dual where 1 = 1
/
define var"

This is a SELECT_EXPRESSION, EXECUTE_PLSQL_BUFFER and SQLPLUS_COMMAND (DEFINE), but it was parsed as a SELECT_EXPRESSION with the operation "1 / define"
  • Loading branch information
felipebz committed Jun 25, 2024
1 parent 6fc3fe1 commit 2172558
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"examples/ex_pljson_table.sql" : [
151,
165,
189
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"examples/ex_pljson_table.sql" : [
200
41,
53,
65
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"examples/ex_pljson_table.sql" : [
129,
224,
249,
294
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,18 @@ enum class PlSqlGrammar : GrammarRuleKey {

b.rule(EXPONENTIATION_EXPRESSION).define(UNARY_EXPRESSION, b.zeroOrMore(EXPONENTIATION, UNARY_EXPRESSION)).skipIfOneChild()

b.rule(MULTIPLICATIVE_EXPRESSION).define(EXPONENTIATION_EXPRESSION, b.zeroOrMore(b.firstOf(MULTIPLICATION, DIVISION, MOD_KEYWORD), EXPONENTIATION_EXPRESSION)).skipIfOneChild()
b.rule(MULTIPLICATIVE_EXPRESSION).define(
EXPONENTIATION_EXPRESSION, b.zeroOrMore(
b.firstOf(
MULTIPLICATION,
b.sequence(
DIVISION,
b.nextNot(FILE_INPUT)
),
MOD_KEYWORD
), EXPONENTIATION_EXPRESSION
)
).skipIfOneChild()

b.rule(ADDITIVE_EXPRESSION).define(MULTIPLICATIVE_EXPRESSION, b.zeroOrMore(b.firstOf(PLUS, MINUS), MULTIPLICATIVE_EXPRESSION)).skipIfOneChild()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
*/
package org.sonar.plugins.plsqlopen.api

import org.sonar.plsqlopen.sslr.PlSqlGrammarBuilder
import com.felipebz.flr.api.GenericTokenType
import com.felipebz.flr.grammar.GrammarRuleKey
import org.sonar.plsqlopen.sslr.PlSqlGrammarBuilder

enum class SqlPlusGrammar : GrammarRuleKey {

Expand Down Expand Up @@ -82,7 +83,7 @@ enum class SqlPlusGrammar : GrammarRuleKey {
"VAR", "VARIABLE",
"WHENEVER",
"XQUERY"),
b.tillNewLine())
b.firstOf(b.tillNewLine(), b.till(GenericTokenType.EOF)))
}
}

Expand Down

0 comments on commit 2172558

Please sign in to comment.