aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJack Koenig2018-03-21 10:53:42 -0700
committerAdam Izraelevitz2018-03-21 10:53:42 -0700
commit6b195e4a5348eed2e714e1183024588c5f91a283 (patch)
tree15f5db0f35e4d613e10ab71a224f656d8a8ff647 /src
parentf55553b1df0ab083f4f53862e6cf200bd9ceab3e (diff)
Add SyntaxErrorsException as a type of ParserException (#770)
Also make ParserException extend FIRRTLException to better report parsing errors to the user
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/Parser.scala8
-rw-r--r--src/test/scala/firrtlTests/ParserSpec.scala14
2 files changed, 17 insertions, 5 deletions
diff --git a/src/main/scala/firrtl/Parser.scala b/src/main/scala/firrtl/Parser.scala
index f40c465e..70ae7739 100644
--- a/src/main/scala/firrtl/Parser.scala
+++ b/src/main/scala/firrtl/Parser.scala
@@ -11,15 +11,13 @@ import firrtl.ir._
import firrtl.Utils.time
import firrtl.antlr.{FIRRTLParser, _}
-class ParserException(message: String) extends Exception(message)
+class ParserException(message: String) extends FIRRTLException(message)
case class ParameterNotSpecifiedException(message: String) extends ParserException(message)
-
case class ParameterRedefinedException(message: String) extends ParserException(message)
-
case class InvalidStringLitException(message: String) extends ParserException(message)
-
case class InvalidEscapeCharException(message: String) extends ParserException(message)
+case class SyntaxErrorsException(message: String) extends ParserException(message)
object Parser extends LazyLogging {
@@ -42,7 +40,7 @@ object Parser extends LazyLogging {
val cst = parser.circuit
val numSyntaxErrors = parser.getNumberOfSyntaxErrors
- if (numSyntaxErrors > 0) throw new ParserException(s"$numSyntaxErrors syntax error(s) detected")
+ if (numSyntaxErrors > 0) throw new SyntaxErrorsException(s"$numSyntaxErrors syntax error(s) detected")
cst
}
diff --git a/src/test/scala/firrtlTests/ParserSpec.scala b/src/test/scala/firrtlTests/ParserSpec.scala
index 4ed16afe..384b75d2 100644
--- a/src/test/scala/firrtlTests/ParserSpec.scala
+++ b/src/test/scala/firrtlTests/ParserSpec.scala
@@ -157,6 +157,20 @@ class ParserSpec extends FirrtlFlatSpec {
val c = firrtl.Parser.parse(input)
firrtl.Parser.parse(c.serialize)
}
+
+ "Parsing errors" should "be reported as normal exceptions" in {
+ val input = s"""
+ |circuit Test
+ | module Test :
+
+ |""".stripMargin
+ val manager = new ExecutionOptionsManager("test") with HasFirrtlOptions {
+ firrtlOptions = FirrtlExecutionOptions(firrtlSource = Some(input))
+ }
+ a [SyntaxErrorsException] shouldBe thrownBy {
+ Driver.execute(manager)
+ }
+ }
}
class ParserPropSpec extends FirrtlPropSpec {