Skip to content

Commit

Permalink
fix: Fix lexer to correctly handle binding and host/indicator variabl…
Browse files Browse the repository at this point in the history
…es (#181)
  • Loading branch information
felipebz committed Feb 29, 2024
1 parent 56b0a67 commit 7744f16
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ enum class PlSqlGrammar : GrammarRuleKey {
}

private fun createStatements(b: PlSqlGrammarBuilder) {
b.rule(HOST_AND_INDICATOR_VARIABLE).define(COLON, IDENTIFIER_NAME, b.optional(COLON, IDENTIFIER_NAME))
b.rule(HOST_AND_INDICATOR_VARIABLE).define(COLON, b.firstOf(
b.sequence(IDENTIFIER_NAME, b.optional(INDICATOR), b.optional(COLON, IDENTIFIER_NAME)),
INTEGER_LITERAL))

b.rule(NULL_STATEMENT, NullStatement::class).define(NULL, SEMICOLON)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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

import com.felipebz.flr.tests.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class HostAndIndicatorVariableTest : RuleTest() {

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

@Test
fun matchesSimpleBindingVariable() {
assertThat(p).matches(":var")
}

@Test
fun matchesSimpleNumericBindingVariable() {
assertThat(p).matches(":1")
}

@Test
fun matchesShortIndicatorVariable() {
assertThat(p).matches(":var:ind")
}

@Test
fun matchesLongIndicatorVariable() {
assertThat(p).matches(":var indicator :ind")
}

}

0 comments on commit 7744f16

Please sign in to comment.