Skip to content

Commit

Permalink
allow uderscore in variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkaczor committed Jul 5, 2021
1 parent 42557f5 commit 847da19
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.sbt
@@ -1,10 +1,10 @@
scalacOptions in ThisBuild ++= Seq("-deprecation", "-feature")
ThisBuild / scalacOptions ++= Seq("-deprecation", "-feature")

organization := "pl.newicom.scalexpr"

name := "scalexpr"

scalaVersion := "2.13.3"
scalaVersion := "2.13.6"

publishMavenStyle := true
homepage := Some(new URL("http://github.com/pawelkaczor/scalexpr"))
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=1.4.5
sbt.version=1.5.4
Expand Up @@ -70,7 +70,7 @@ class ExpressionParser extends DateParser {
// ---------------------------------------------------------------
// ----------------- General parsers ----------------------
// ---------------------------------------------------------------
def chars[_: P]: P[Unit] = P(CharIn("a-zA-Z"))
def chars[_: P]: P[Unit] = P(CharIn("a-zA-Z_"))
def digits[_: P]: P[Unit] = P(CharIn("0-9"))

// ---------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/br/com/virsox/scalexpr/ExpressionParserTest.scala
Expand Up @@ -100,6 +100,13 @@ class ExpressionParserTest extends AnyFlatSpec with Matchers {
)
}

it should "parse relational expression with a var containing underscore" in new Fixture {
verify(
parser.parseRelationalExpression("""a_var > 5"""),
RelationalExpression(BigDecimalVar("a_var"), GreaterThan, BigDecimalConstant(5))
)
}

it should "parse comparison expressions with variables on both sides" in new Fixture {
verify(parser.parseBooleanExpression("""a == b"""), BigDecimalVar("a") == BigDecimalVar("b"))
verify(parser.parseBooleanExpression("""a != b"""), BigDecimalVar("a") != BigDecimalVar("b"))
Expand Down Expand Up @@ -154,6 +161,14 @@ class ExpressionParserTest extends AnyFlatSpec with Matchers {
)
}

it should "parse boolean expressions with parenthesis 2" in new Fixture {
verify(
parser.parseBooleanExpression("""isFirst == 1 || (name == "Test" && age == 19)"""),
(BigDecimalVar("isFirst") == BigDecimalConstant(1)) ||
((StringVar("name") == StringConstant("Test")) && (BigDecimalVar("age") == BigDecimalConstant(19)))
)
}

it should "parse complex boolean expressions with parenthesis" in new Fixture {
verify(
parser.parseBooleanExpression("""(name == "Wilson" && age > (base + 2.0)) || (name == "Test" && age == ( 4 * 2))"""),
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
@@ -1 +1 @@
version in ThisBuild := "0.1.2"
ThisBuild / version := "0.1.3"

0 comments on commit 847da19

Please sign in to comment.