Skip to content

Commit

Permalink
Give position information on parser errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoblenz committed Jan 21, 2020
1 parent 20f4737 commit c21e62f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/edu/cmu/cs/obsidian/lexer/TokenReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.util.parsing.input._

class TokenReader(tokens : Seq[Token]) extends Reader[Token] {
override def atEnd : Boolean = tokens.isEmpty
override def pos: Position = NoPosition
override def pos: Position = if (atEnd) NoPosition else first.pos

override def first : Token = tokens.head
override def rest : Reader[Token] = new TokenReader(tokens.tail)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/cmu/cs/obsidian/parser/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ object Parser extends Parsers {
val reader = new TokenReader(tokens)
parseProgram(srcPath)(reader) match {
case Success(result, _) => Right(result)
case Failure(msg , _) => Left(s"PARSER FAILURE: $msg")
case Failure(msg, reader) => Left(s"Parser failure at ${reader.pos}: $msg")
case Error(msg , next) =>
if (next.atEnd) {
Left(s"Parser Error: $msg at end of file")
Expand Down

0 comments on commit c21e62f

Please sign in to comment.