fix: make parser use only parsley parser bridge apply
This commit is contained in:
@@ -93,10 +93,7 @@ object parser {
|
||||
private val `<ident>` = Ident(ident)
|
||||
private lazy val `<ident-or-array-elem>` =
|
||||
`<ident>` <**> (`<array-indices>` </> identity)
|
||||
private val `<array-indices>` =
|
||||
some("[" ~> `<expr>` <~ "]") map { indices =>
|
||||
ArrayElem((_: Ident), indices)
|
||||
}
|
||||
private val `<array-indices>` = ArrayElem(some("[" ~> `<expr>` <~ "]"))
|
||||
|
||||
// Types
|
||||
private lazy val `<type>`: Parsley[Type] =
|
||||
@@ -104,7 +101,7 @@ object parser {
|
||||
private val `<base-type>` =
|
||||
(IntType from "int") | (BoolType from "bool") | (CharType from "char") | (StringType from "string")
|
||||
private lazy val `<array-type>` =
|
||||
countSome("[" ~> "]") map { cnt => ArrayType((_: Type), cnt) }
|
||||
ArrayType(countSome("[" ~> "]"))
|
||||
private val `<pair-type>` = "pair"
|
||||
private val `<pair-elems-type>`: Parsley[PairType] = PairType(
|
||||
"(" ~> `<pair-elem-type>` <~ ",",
|
||||
@@ -112,10 +109,10 @@ object parser {
|
||||
)
|
||||
private lazy val `<pair-elem-type>` =
|
||||
(`<base-type>` <**> (`<array-type>` </> identity)) |
|
||||
`<pair-type>` ~> ((`<pair-elems-type>` <**> `<array-type>`.explain(
|
||||
"non-erased pair types cannot be nested"
|
||||
)) </> UntypedPairType)
|
||||
// TODO: better explanation here?
|
||||
((UntypedPairType from `<pair-type>`) <**>
|
||||
((`<pair-elems-type>` <**> `<array-type>`)
|
||||
.map(arr => (_: UntypedPairType) => arr) </> identity))
|
||||
|
||||
// Statements
|
||||
private lazy val `<program>` = Program(
|
||||
"begin" ~> many(
|
||||
@@ -124,11 +121,12 @@ object parser {
|
||||
`<stmt>`.label("main program body") <~ "end"
|
||||
)
|
||||
private lazy val `<partial-func-decl>` =
|
||||
(sepBy(`<param>`, ",") <~ ")" <~ "is" <~> `<stmt>`.guardAgainst {
|
||||
case stmts if !stmts.isReturning => Seq("all functions must end in a returning statement")
|
||||
} <~ "end") map { (params, stmt) =>
|
||||
(FuncDecl((_: Type), (_: Ident), params, stmt)).tupled
|
||||
}
|
||||
FuncDecl(
|
||||
sepBy(`<param>`, ",") <~ ")" <~ "is",
|
||||
`<stmt>`.guardAgainst {
|
||||
case stmts if !stmts.isReturning => Seq("All functions must end in a returning statement")
|
||||
} <~ "end"
|
||||
)
|
||||
private lazy val `<param>` = Param(`<type>`, `<ident>`)
|
||||
private lazy val `<stmt>`: Parsley[NonEmptyList[Stmt]] =
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user