Skip to content

Improve Dottydoc error reporting #7350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions doc-tool/src/dotty/tools/dottydoc/staticsite/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ case class LiquidTemplate(path: String, content: SourceFile) extends Template wi
val unexpected = LiquidTemplate.token(mm.getUnexpectedType)
val expected = LiquidTemplate.token(mm.expecting)

// mm.index is incorrect, let's compute the index manually
// mm.line starts at 1, not 0
val index = content.lineToOffset(mm.line-1) + mm.charPositionInLine
ctx.error(
if (unexpected == "EOF")
s"unexpected end of file, expected: '$expected'"
s"unexpected end of file, expected $expected"
else
s"unexpected token '$unexpected', expected: '$expected'",
content atSpan Span(mm.index)
s"unexpected $unexpected, expected $expected",
content atSpan Span(index)
)

None
}
case ex => {
if (true || ctx.settings.Ydebug.value)
case _ => {
throw ex

None
}
}
}
Expand All @@ -98,17 +98,37 @@ case class LiquidTemplate(path: String, content: SourceFile) extends Template wi

object LiquidTemplate {
import liqp.parser.LiquidParser
import scala.collection.mutable.HashMap

private val _tokens: Map[String, String] = Map(
final val TokenSymbols = HashMap(
"TagStart" -> "{%",
"TagEnd" -> "%}"
)
"TagEnd" -> "%}",
"OutStart" -> "{{",
"OutEnd" -> "}}",
"Pipe" -> "|",
"DotDot" -> "..",
"Dot" -> ".",
"Eq" -> "==",
"EqSign" -> "=",
"Gt" -> ">",
"GtEq" -> ">=",
"Lt" -> "<",
"LtEq" -> "<=",
"Minus" -> "-",
"Col" -> ":",
"Comma" -> ",",
"OPar" -> "(",
"CPar" -> ")",
"OBr" -> "[",
"CBr" -> "]",
"QMark" -> "?"
).mapValuesInPlace((k,v) => s"'$v' ($k)")

def token(i: Int): String =
if (i == -1) "EOF"
else if (i >= LiquidParser.tokenNames.length)
"non-existing token"
else _tokens
.get(LiquidParser.tokenNames(i))
.getOrElse(s"token $i")
else if (i >= LiquidParser.tokenNames.length) "non-existing token"
else {
val name = LiquidParser.tokenNames(i)
TokenSymbols.getOrElse(name, name)
}
}