aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Magyar2019-11-04 12:34:13 -0800
committermergify[bot]2019-11-04 20:34:13 +0000
commit8f108c1aa8cac656da56b2505519db47080d5a26 (patch)
tree63bbe70175c9af57f08f7864ddfb3cb4298c9a8c /src
parent4c3c7e328e41f289ec37aee85a5d4d15c7b18189 (diff)
Add explicit EOF to top-level parser rule (#1217)
* Fixes #1154 * Tests that #1154 example produces SyntaxErrorsException * Generally helps catch trailing syntax errors * Performance-neutral relative to previous grammar * Recommended by antlr4 devs, can help performance in some cases * See antlr/antlr4#1540
Diffstat (limited to 'src')
-rw-r--r--src/main/antlr4/FIRRTL.g42
-rw-r--r--src/test/scala/firrtlTests/ParserSpec.scala23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/main/antlr4/FIRRTL.g4 b/src/main/antlr4/FIRRTL.g4
index 518cb698..0035423b 100644
--- a/src/main/antlr4/FIRRTL.g4
+++ b/src/main/antlr4/FIRRTL.g4
@@ -29,7 +29,7 @@ import firrtl.LexerHelper;
// Does there have to be at least one module?
circuit
- : 'circuit' id ':' info? INDENT module* DEDENT
+ : 'circuit' id ':' info? INDENT module* DEDENT EOF
;
module
diff --git a/src/test/scala/firrtlTests/ParserSpec.scala b/src/test/scala/firrtlTests/ParserSpec.scala
index 711df5ed..4f28e100 100644
--- a/src/test/scala/firrtlTests/ParserSpec.scala
+++ b/src/test/scala/firrtlTests/ParserSpec.scala
@@ -169,6 +169,29 @@ class ParserSpec extends FirrtlFlatSpec {
Driver.execute(manager)
}
}
+
+ "Trailing syntax errors" should "be caught in the parser" in {
+ val input = s"""
+ |circuit Foo:
+ | module Bar:
+ | input a: UInt<1>
+ |output b: UInt<1>
+ | b <- a
+ |
+ | module Foo:
+ | input a: UInt<1>
+ | output b: UInt<1>
+ | inst bar of Bar
+ | bar.a <- a
+ | b <- bar.b
+ """.stripMargin
+ val manager = new ExecutionOptionsManager("test") with HasFirrtlOptions {
+ firrtlOptions = FirrtlExecutionOptions(firrtlSource = Some(input))
+ }
+ a [SyntaxErrorsException] shouldBe thrownBy {
+ Driver.execute(manager)
+ }
+ }
}
class ParserPropSpec extends FirrtlPropSpec {