Skip to content

Commit 1e20c8b

Browse files
committed
Fixed syntax
1 parent 2fd566f commit 1e20c8b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ThisBuild / publishTo := {
2929
}
3030
ThisBuild / publishMavenStyle := true
3131

32-
ThisBuild / version := "0.9.0"
32+
ThisBuild / version := "0.9.1"
3333

3434
lazy val scala212 = "2.12.10"
3535
lazy val scala213 = "2.13.1"

core/src/main/scala/de/upb/cs/swt/delphi/core/ql/Syntax.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ class Syntax(val input : ParserInput) extends Parser {
6767
def IsTrue = rule { FieldReferenceRule ~> IsTrueExpr }
6868

6969
// Literals
70-
def FieldReferenceRule = rule { "[" ~ capture(oneOrMore(CharPredicate.AlphaNum ++ '-' ++ ' ' ++ '_' ++ '(' ++ ':' ++')')) ~ "]" ~> FieldReference }
70+
def FieldReferenceRule = rule { "[" ~ capture(oneOrMore(CharPredicate.AlphaNum ++ '.' ++ '-' ++ ' ' ++ '_' ++ '(' ++ ':' ++')')) ~ "]" ~> FieldReference }
7171

7272
def IntegerLiteral = rule { capture(oneOrMore(CharPredicate.Digit)) }
73-
def StringLiteral = rule { '"' ~ capture(oneOrMore(CharPredicate.AlphaNum)) ~ '"'}
73+
def StringLiteral = rule { '"' ~ capture(oneOrMore(CharPredicate.Printable -- '"' )) ~ '"'}
7474

7575
def Literal = rule { (IntegerLiteral | StringLiteral ) ~> (_.toString) }
7676

core/src/test/scala/de/upb/cs/swt/delphi/core/SyntaxTest.scala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package de.upb.cs.swt.delphi.core
1818

19-
import de.upb.cs.swt.delphi.core.ql.Syntax
19+
import de.upb.cs.swt.delphi.core.ql._
20+
import org.parboiled2.ParseError
2021
import org.scalatest.{FlatSpec, Matchers}
2122

2223
import scala.util.{Failure, Success}
@@ -166,7 +167,7 @@ class SyntaxTest extends FlatSpec with Matchers {
166167

167168
"Syntax.notConditionComplex" should "be valid" in {
168169
val parseResult = new Syntax("!!([Filter1])&&!([Filter2]<=0||!([Filter3]&&![Filter4]%\"abc\"))").QueryRule.run()
169-
parseResult shouldBe a [Success[_]]
170+
parseResult shouldBe a[Success[_]]
170171
parseResult match {
171172
case Success(ast) => {
172173
ast.toString shouldEqual "AndExpr(NotExpr(NotExpr(IsTrueExpr(FieldReference(Filter1))))," +
@@ -175,4 +176,23 @@ class SyntaxTest extends FlatSpec with Matchers {
175176
}
176177
}
177178
}
179+
180+
"Complex query" should "be valid" in {
181+
val parser = new Syntax("[metrics.classversion.9] > 0 && [metrics.classversion.8] = 0 && [maven.groupId] = \"com.github.xmlet\"")
182+
val parseResult = parser.QueryRule.run()
183+
parseResult match {
184+
case Success(ast) => {
185+
ast shouldEqual
186+
AndExpr(
187+
AndExpr(
188+
GreaterThanExpr(FieldReference("metrics.classversion.9"),"0"),
189+
EqualExpr(FieldReference("metrics.classversion.8"),"0")),
190+
EqualExpr(FieldReference("maven.groupId"),"com.github.xmlet"))
191+
}
192+
case Failure(exception : ParseError) => {
193+
fail(parser.formatError(exception))
194+
}
195+
case _ => fail()
196+
}
197+
}
178198
}

0 commit comments

Comments
 (0)