diff options
| author | jackkoenig | 2016-03-14 22:35:06 -0700 |
|---|---|---|
| committer | jackkoenig | 2016-03-15 13:43:57 -0700 |
| commit | 373d3cfcb5566c448dcad6b679dee43bf66f878a (patch) | |
| tree | 6a80e496588f56f5c52be40bcc0155ba8987811a /src/main/scala/firrtl/Translator.scala | |
| parent | 5737a8ccbf54a6d22095023205867e851e204c3f (diff) | |
Revamp string literal handling
Diffstat (limited to 'src/main/scala/firrtl/Translator.scala')
| -rw-r--r-- | src/main/scala/firrtl/Translator.scala | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/Translator.scala b/src/main/scala/firrtl/Translator.scala index 1ca20346..07dd1b42 100644 --- a/src/main/scala/firrtl/Translator.scala +++ b/src/main/scala/firrtl/Translator.scala @@ -26,11 +26,9 @@ MODIFICATIONS. */ /* TODO - * - Add support for comments (that being said, current Scopers regex should ignore commented lines) * - Add better error messages for illformed FIRRTL * - Add support for files that do not have a circuit (like a module by itself in a file) * - Improve performance? Replace regex? - * - Add proper commnad-line arguments? * - Wrap in Reader subclass. This would have less memory footprint than creating a large string */ @@ -47,7 +45,27 @@ object Translator def addBrackets(inputIt: Iterator[String]): StringBuilder = { def countSpaces(s: String): Int = s.prefixLength(_ == ' ') - def stripComments(s: String): String = s takeWhile (!";".contains(_)) + def stripComments(s: String): String = { + // Delete anything after first semicolon that's not in a comment + var done = false + var inComment = false + var escape = false + var i = 0 + while (!done && i < s.length) { + val c = s(i) + if (c == ';') { + if (!inComment) { + done = true + i = i - 1 // remove semicolon as well as what follows + } + } else { + if (c == '"' && !escape) inComment = !inComment + escape = if (c == '\\' && !escape) true else false + } + i += 1 + } + s.take(i) + } val scopers = """(circuit|module|when|else|mem|with)""" val MultiLineScope = ("""(.*""" + scopers + """)(.*:\s*)""").r |
