feat: use NoneEmptyList from cats to enfroce non-empty statements
This commit is contained in:
parent
1643628c60
commit
1d78072c22
@ -3,6 +3,7 @@
|
||||
|
||||
// dependencies
|
||||
//> using dep com.github.j-mie6::parsley::5.0.0-M10
|
||||
//> using dep com.github.j-mie6::parsley-cats::1.3.0
|
||||
//> using dep com.lihaoyi::os-lib::0.11.3
|
||||
//> using dep com.github.scopt::scopt::4.1.0
|
||||
//> using test.dep org.scalatest::scalatest::3.2.19
|
||||
|
@ -1,6 +1,7 @@
|
||||
package wacc
|
||||
|
||||
import parsley.generic._
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
object ast {
|
||||
// Expressions
|
||||
@ -24,8 +25,8 @@ object ast {
|
||||
case object PairLiter extends Expr6 with ParserBridge0[PairLiter.type]
|
||||
case class Ident(v: String) extends Expr6 with LValue
|
||||
object Ident extends ParserBridge1[String, Ident]
|
||||
case class ArrayElem(name: Ident, indices: List[Expr]) extends Expr6 with LValue
|
||||
object ArrayElem extends ParserBridge2[Ident, List[Expr], ArrayElem]
|
||||
case class ArrayElem(name: Ident, indices: NonEmptyList[Expr]) extends Expr6 with LValue
|
||||
object ArrayElem extends ParserBridge2[Ident, NonEmptyList[Expr], ArrayElem]
|
||||
case class Parens(expr: Expr) extends Expr6
|
||||
object Parens extends ParserBridge1[Expr, Parens]
|
||||
|
||||
@ -85,17 +86,17 @@ object ast {
|
||||
case object UntypedPairType extends PairElemType with ParserBridge0[UntypedPairType.type]
|
||||
|
||||
// waccadoodledo
|
||||
case class Program(funcs: List[FuncDecl], main: List[Stmt])
|
||||
object Program extends ParserBridge2[List[FuncDecl], List[Stmt], Program]
|
||||
case class Program(funcs: List[FuncDecl], main: NonEmptyList[Stmt])
|
||||
object Program extends ParserBridge2[List[FuncDecl], NonEmptyList[Stmt], Program]
|
||||
|
||||
// Function Definitions
|
||||
case class FuncDecl(
|
||||
returnType: Type,
|
||||
name: Ident,
|
||||
params: List[Param],
|
||||
body: List[Stmt]
|
||||
body: NonEmptyList[Stmt]
|
||||
)
|
||||
object FuncDecl extends ParserBridge4[Type, Ident, List[Param], List[Stmt], FuncDecl]
|
||||
object FuncDecl extends ParserBridge4[Type, Ident, List[Param], NonEmptyList[Stmt], FuncDecl]
|
||||
|
||||
case class Param(paramType: Type, name: Ident)
|
||||
object Param extends ParserBridge2[Type, Ident, Param]
|
||||
@ -117,12 +118,12 @@ object ast {
|
||||
object Exit extends ParserBridge1[Expr, Exit]
|
||||
case class Print(expr: Expr, newline: Boolean) extends Stmt
|
||||
object Print extends ParserBridge2[Expr, Boolean, Print]
|
||||
case class If(cond: Expr, thenStmt: List[Stmt], elseStmt: List[Stmt]) extends Stmt
|
||||
object If extends ParserBridge3[Expr, List[Stmt], List[Stmt], If]
|
||||
case class While(cond: Expr, body: List[Stmt]) extends Stmt
|
||||
object While extends ParserBridge2[Expr, List[Stmt], While]
|
||||
case class Block(stmt: List[Stmt]) extends Stmt
|
||||
object Block extends ParserBridge1[List[Stmt], Block]
|
||||
case class If(cond: Expr, thenStmt: NonEmptyList[Stmt], elseStmt: NonEmptyList[Stmt]) extends Stmt
|
||||
object If extends ParserBridge3[Expr, NonEmptyList[Stmt], NonEmptyList[Stmt], If]
|
||||
case class While(cond: Expr, body: NonEmptyList[Stmt]) extends Stmt
|
||||
object While extends ParserBridge2[Expr, NonEmptyList[Stmt], While]
|
||||
case class Block(stmt: NonEmptyList[Stmt]) extends Stmt
|
||||
object Block extends ParserBridge1[NonEmptyList[Stmt], Block]
|
||||
|
||||
sealed trait LValue
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user