Skip to content

Commit

Permalink
Enable parsing of nested tuple expression
Browse files Browse the repository at this point in the history
  • Loading branch information
dlindhol committed May 4, 2021
1 parent 9bfdb26 commit 2004d17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/src/test/scala/latis/model/ModelParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ object ModelParser {
r <- dataType.token
} yield Function(d, r)

/** Only parses tuples of scalars */
//TODO: support functions in tuples
def tuple: Parser[DataType] = for {
l <- parens(sepBy(scalar.token, char(',').token))
//l <- parens(sepBy(dataType.token, char(',').token)) //stack overflow
l <- parens(sepBy((scalar | tuple).token, char(',').token))
} yield Tuple(l)

def scalar: Parser[DataType] =
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/scala/latis/model/ModelParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ class ModelParserSpec extends AnyFlatSpec {
)
}

it should "parse a nested tuple" in {
ModelParser.unsafeParse("(a, (b, c))") match {
case Tuple(a: Scalar, Tuple(b: Scalar, c: Scalar)) =>
a.id.get should be (id"a")
b.id.get should be (id"b")
c.id.get should be (id"c")
}
}

ignore should "parse a function in a tuple" in {
ModelParser.unsafeParse("(a, b -> c)") match {
case Tuple(a: Scalar, Function(b: Scalar, c: Scalar)) =>
a.id.get should be (id"a")
b.id.get should be (id"b")
c.id.get should be (id"c")
}
}

it should "parse a function" in {
testFunction(
"a: int -> b: double",
Expand Down

0 comments on commit 2004d17

Please sign in to comment.