diff --git a/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala b/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala index c58b4eeb..85f53b7b 100644 --- a/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala +++ b/modules/parser-gen/src/main/scala/playground/parsergen/ParserGen.scala @@ -55,10 +55,11 @@ def renderAdt(tpe: NodeType) = { } val projections = tpe.subtypes.map { nodeType => + // UNSAFE: inexhaustive match // format: off show"""def ${nodeType.tpe.renderProjection}: ${nodeType .tpe - .render} = this match { case ${nodeType.tpe.asEnumCase.render}(v) => v; case _ => sys.error("no match") }""" + .render} = this match { case ${nodeType.tpe.asEnumCase.render}(v) => v }""" // format: on } @@ -143,7 +144,7 @@ def renderClass(tpe: NodeType) = { |${cases.mkString("\n").indentTrim(2)} |}""".stripMargin else - // todo replace head with a stricter "only" check? + // UNSAFE: head show"""$allFields.head match { |${cases.mkString("\n").indentTrim(2)} |}""".stripMargin @@ -174,6 +175,7 @@ def renderClass(tpe: NodeType) = { |${cases.mkString("\n").indentTrim(2)} |}""".stripMargin else + // UNSAFE: head show"""$allChildren.head match { |${cases.mkString("\n").indentTrim(2)} |}""".stripMargin @@ -200,6 +202,7 @@ def renderClass(tpe: NodeType) = { .render}() => ${fieldType.tpe.render}(node) |}""".stripMargin else + // UNSAFE: get show"""node.children.collectFirst { | case node @ ${fieldType.tpe.render}() => ${fieldType.tpe.render}(node) |}.get""".stripMargin diff --git a/modules/parser/src/main/scala/playground/generated/nodes/InputNode.scala b/modules/parser/src/main/scala/playground/generated/nodes/InputNode.scala index 57425150..a39391be 100644 --- a/modules/parser/src/main/scala/playground/generated/nodes/InputNode.scala +++ b/modules/parser/src/main/scala/playground/generated/nodes/InputNode.scala @@ -11,12 +11,12 @@ enum InputNode { case StringCase(value: String_) case StructCase(value: Struct) - def asBoolean: Boolean_ = this match { case BooleanCase(v) => v; case _ => sys.error("no match") } - def asList: List_ = this match { case ListCase(v) => v; case _ => sys.error("no match") } - def asNull: Null_ = this match { case NullCase(v) => v; case _ => sys.error("no match") } - def asNumber: Number = this match { case NumberCase(v) => v; case _ => sys.error("no match") } - def asString: String_ = this match { case StringCase(v) => v; case _ => sys.error("no match") } - def asStruct: Struct = this match { case StructCase(v) => v; case _ => sys.error("no match") } + def asBoolean: Boolean_ = this match { case BooleanCase(v) => v } + def asList: List_ = this match { case ListCase(v) => v } + def asNull: Null_ = this match { case NullCase(v) => v } + def asNumber: Number = this match { case NumberCase(v) => v } + def asString: String_ = this match { case StringCase(v) => v } + def asStruct: Struct = this match { case StructCase(v) => v } def node: Node = this match { case BooleanCase(value) => value.node