Skip to content

Commit

Permalink
Add a grammar rule for table expression ("table(...)")
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Mar 3, 2022
1 parent f092134 commit 972cbd7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
package org.sonar.plugins.plsqlopen.api

import com.felipebz.flr.grammar.GrammarRuleKey
import org.sonar.plsqlopen.sslr.PlSqlGrammarBuilder
import org.sonar.plugins.plsqlopen.api.DmlGrammar.ORDER_BY_CLAUSE
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar.*
import org.sonar.plugins.plsqlopen.api.PlSqlKeyword.*
import org.sonar.plugins.plsqlopen.api.PlSqlPunctuator.*
import org.sonar.plugins.plsqlopen.api.PlSqlTokenType.STRING_LITERAL
import com.felipebz.flr.grammar.GrammarRuleKey

enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {

Expand Down Expand Up @@ -54,6 +54,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {
XMLTABLE_EXPRESSION,
CAST_EXPRESSION,
TRIM_EXPRESSION,
TABLE_EXPRESSION,
SINGLE_ROW_SQL_FUNCTION;

companion object {
Expand All @@ -79,7 +80,8 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {
XMLPI_EXPRESSION,
XMLTABLE_EXPRESSION,
CAST_EXPRESSION,
TRIM_EXPRESSION)).skip()
TRIM_EXPRESSION,
TABLE_EXPRESSION)).skip()
}

private fun createCharacterFunctions(b: PlSqlGrammarBuilder) {
Expand All @@ -95,6 +97,11 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {
b.firstOf(b.sequence(MULTISET, EXPRESSION), EXPRESSION),
AS, DATATYPE,
RPARENTHESIS)

b.rule(TABLE_EXPRESSION).define(
TABLE, LPARENTHESIS,
EXPRESSION,
RPARENTHESIS)
}

private fun createDateFunctions(b: PlSqlGrammarBuilder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Z PL/SQL Analyzer
* Copyright (C) 2015-2022 Felipe Zorzo
* mailto:felipe AT felipezorzo DOT com DOT br
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.plsqlopen.api.expressions

import com.felipebz.flr.tests.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import org.sonar.plugins.plsqlopen.api.RuleTest

class TableExpressionTest : RuleTest() {

@BeforeEach
fun init() {
setRootRule(PlSqlGrammar.EXPRESSION)
}

@Test
fun matchesSimpleTable() {
assertThat(p).matches("table(foo)")
}

}

0 comments on commit 972cbd7

Please sign in to comment.