Skip to content

Commit

Permalink
feat(grammar): Support JSON constructor (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 31, 2024
1 parent efc977e commit 460e813
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {

// functions
EXTRACT_DATETIME_EXPRESSION,
JSON_CONSTRUCTOR,
JSON_QUERY_EXPRESSION,
XMLATTRIBUTES_EXPRESSION,
XMLELEMENT_EXPRESSION,
Expand Down Expand Up @@ -78,6 +79,7 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {
b.rule(SINGLE_ROW_SQL_FUNCTION).define(
b.firstOf(
EXTRACT_DATETIME_EXPRESSION,
JSON_CONSTRUCTOR,
JSON_QUERY_EXPRESSION,
XMLATTRIBUTES_EXPRESSION,
XMLELEMENT_EXPRESSION,
Expand Down Expand Up @@ -256,6 +258,8 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey {
}

private fun createJsonFunctions(b: PlSqlGrammarBuilder) {
b.rule(JSON_CONSTRUCTOR).define(JSON, LPARENTHESIS, EXPRESSION, RPARENTHESIS)

b.rule(JSON_QUERY_EXPRESSION).define(
JSON_QUERY,
LPARENTHESIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Z PL/SQL Analyzer
* Copyright (C) 2015-2024 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 JsonConstructorTest : RuleTest() {

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

@Test
fun matches() {
assertThat(p).matches("json('{}')")
}

}

0 comments on commit 460e813

Please sign in to comment.