diff options
| author | Jack | 2016-02-02 11:49:38 -0800 |
|---|---|---|
| committer | azidar | 2016-02-09 18:57:06 -0800 |
| commit | b2d9eacd26e8283f438bc6429770497290d5b9c3 (patch) | |
| tree | 4eff98b858a049bc533a6fcaf10888a331c6e773 /src/main/scala/firrtl/Parser.scala | |
| parent | 43ecab5aec6751d05ac986570e0648bb3d90982a (diff) | |
Adding ScalaTest for unit testing of Scala FIRRTL. Added a few basic tests for the Parser. Added custom Parser exceptions for better error reporting and checking. Fixed bug in grammar not allowing most keywords as Ids
Diffstat (limited to 'src/main/scala/firrtl/Parser.scala')
| -rw-r--r-- | src/main/scala/firrtl/Parser.scala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/Parser.scala b/src/main/scala/firrtl/Parser.scala index 98864e92..41426357 100644 --- a/src/main/scala/firrtl/Parser.scala +++ b/src/main/scala/firrtl/Parser.scala @@ -3,13 +3,18 @@ package firrtl import org.antlr.v4.runtime._; import org.antlr.v4.runtime.atn._; import org.antlr.v4.runtime.tree._; +import com.typesafe.scalalogging.LazyLogging import java.io.FileInputStream import scala.collection.JavaConverters._ import scala.io.Source import Utils._ import antlr._ -object Parser +class ParserException(message: String) extends Exception(message) +case class ParameterNotSpecifiedException(message: String) extends ParserException(message) +case class ParameterRedefinedException(message: String) extends ParserException(message) + +object Parser extends LazyLogging { /** Takes Iterator over lines of FIRRTL, returns AST (root node is Circuit) * @@ -17,6 +22,7 @@ object Parser */ def parse(filename: String, lines: Iterator[String]): Circuit = { val fixedInput = Translator.addBrackets(lines) + //logger.debug("Preprocessed Input:\n" + fixedInput.result) val antlrStream = new ANTLRInputStream(fixedInput.result) val lexer = new FIRRTLLexer(antlrStream) val tokens = new CommonTokenStream(lexer) @@ -28,6 +34,9 @@ object Parser // Concrete Syntax Tree val cst = parser.circuit + val numSyntaxErrors = parser.getNumberOfSyntaxErrors + if (numSyntaxErrors > 0) throw new ParserException(s"${numSyntaxErrors} syntax error(s) detected") + val visitor = new Visitor(filename) //val ast = visitor.visitCircuit(cst) match { val ast = visitor.visit(cst) match { |
