Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Oct 18, 2018
1 parent 24721a2 commit 19e0fd0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion demo/src/demo/DemoMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object DemoMain {
tr(td("Failure!")),
tr(td("at index:"), td(code(index))),
tr(td("found:"), td("...", code(pretty))),
tr(td("expected:"), td(code(extra.trace().failureLabel)))
tr(td("expected:"), td(code(extra.trace().label)))
)
}
outputBox.innerHTML = ""
Expand Down
12 changes: 6 additions & 6 deletions fastparse/src/fastparse/Parsed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ object Parsed{
/**
* The outcome of a failed parse
*
* @param failureLabel A hint as to why the parse failed. Defaults to "",
* @param label A hint as to why the parse failed. Defaults to "",
* unless you set `verboseFailures = true` or call
* `.trace()` on an existing failure
* @param index The index at which the parse failed
* @param extra Metadata about the parse; useful for re-running the parse
* to trace out a more detailed error report
*/
final case class Failure(failureLabel: String,
final case class Failure(label: String,
index: Int,
extra: Extra) extends Parsed[Nothing](false){
def get = throw new Exception("Parse Error, " + msg)
def fold[V](onFailure: (String, Int, Extra) => V, onSuccess: (Nothing, Int) => V) = onFailure(failureLabel, index, extra)
def fold[V](onFailure: (String, Int, Extra) => V, onSuccess: (Nothing, Int) => V) = onFailure(label, index, extra)
override def toString() = s"Parsed.Failure($msg)"

/**
* Displays the failure message excluding the parse stack
*/
def msg = {
failureLabel match{
label match{
case "" =>
"Position " + extra.input.prettyIndex(index) +
", found " + Failure.formatTrailing(extra.input, index)
Expand All @@ -72,7 +72,7 @@ object Parsed{
*/
def longMsg = {
if (extra.stack.nonEmpty) {
Failure.formatMsg(extra.input, extra.stack ++ List(failureLabel -> index), index)
Failure.formatMsg(extra.input, extra.stack ++ List(label -> index), index)
} else throw new Exception(
"`.longMsg` requires the parser to be run with `verboseFailures = true`, " +
"or to be called via `.trace().longMsg` or `.trace().longAggregateMsg`"
Expand Down Expand Up @@ -154,7 +154,7 @@ object Parsed{
*/
case class TracedFailure(failureAggregate: Seq[String],
failure: Failure){
def failureLabel = failure.failureLabel
def label = failure.label
def index = failure.index
def input = failure.extra.input
def stack = failure.extra.stack
Expand Down
6 changes: 3 additions & 3 deletions fastparse/test/src/fastparse/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ object ExampleTests extends TestSuite{
val Parsed.Success(value, successIndex) = parse("a", parseA(_))
assert(value == (), successIndex == 1)

val f @ Parsed.Failure(failureLabel, index, extra) = parse("b", parseA(_))
val f @ Parsed.Failure(label, index, extra) = parse("b", parseA(_))
assert(
failureLabel == "",
label == "",
index == 0,
f.msg == """Position 1:1, found "b""""
)
Expand All @@ -43,7 +43,7 @@ object ExampleTests extends TestSuite{
// `.msg` records the last parser that failed, which is "c", and
// `.longMsg` also shows the parsing stack at point of failure
assert(
trace.failureLabel == "\"c\"",
trace.label == "\"c\"",
trace.index == 0,
trace.msg == """Expected "c":1:1, found "d"""",
trace.longMsg == """Expected parseA:1:1 / "c":1:1, found "d""""
Expand Down

0 comments on commit 19e0fd0

Please sign in to comment.