Skip to content

Commit

Permalink
Fixed overwide carets in trivial errors, hints from adjusting unexpec…
Browse files Browse the repository at this point in the history
…ted size to 0, and hints from getting reborn during an iterative combinator (#174)
  • Loading branch information
j-mie6 authored Mar 16, 2023
1 parent 08c6015 commit 15dce75
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private [internal] case class TrivialError(offset: Int, line: Int, col: Int,
builder.unexpected(unexpectedTok.toOption.map(_._1)),
builder.expected(builder.combineExpectedItems(expecteds.map(_.formatExpect))),
builder.combineMessages(reasons.map(builder.reason(_)).toSeq),
builder.lineInfo(line, beforeLines, afterLines, caret, caretSize))
builder.lineInfo(line, beforeLines, afterLines, caret, math.min(caretSize, line.length-caret)))
}
}
private [internal] case class FancyError(offset: Int, line: Int, col: Int, msgs: List[String], caretWidth: Int, lexicalError: Boolean) extends ParseError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private [parsley] final class Context(private [machine] var instrs: Array[Instr]

private [machine] def updateCheckOffsetAndHints() = {
this.checkStack.offset = this.offset
this.hintsValidOffset = this.offset
//this.hintsValidOffset = this.offset // FIXME: verify that this is ok to remove, it seems stupid now that I think about it
}

// $COVERAGE-OFF$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@ private [errors] final class HintCollector(hints: mutable.Set[ExpectItem]) {
/** Creates a new collector that starts empty */
def this() = this(mutable.Set.empty)

private var width = 0
private var width = Option.empty[Int]

/** Adds a new hint into the collector. */
def +=(hint: ExpectItem): Unit = this.hints += hint
/** Adds several hints into the collector. */
def ++=(hints: Iterable[ExpectItem]): Unit = this.hints ++= hints

/** Gets the width of the unexpected token that may have accompanied the original hints */
def unexpectWidth: Int = width
def unexpectWidth: Option[Int] = width
/** Updates the width of the unexpected token that may have accompanied these hints: this
* can only get wider.
*/
def updateWidth(sz: Int): Unit = width = Math.max(width, sz)
def updateWidth(sz: Int): Unit = width = Some(Math.max(width.getOrElse(0), sz))

/** Generates an immutable snapshot of this collector */
def mkSet: Set[ExpectItem] = this.hints.toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ private [errors] final class WithHints private [errors] (val err: TrivialDefuncE
override def makeTrivial(builder: TrivialErrorBuilder): Unit = {
err.makeTrivial(builder)
builder.whenAcceptingExpected {
val size = hints.updateExpectedsAndGetSize(builder)
builder.updateUnexpected(size)
for (size <- hints.updateExpectedsAndGetSize(builder)) builder.updateUnexpected(size)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private [machine] sealed abstract class DefuncHints {
/** This function evaluates this `DefuncHints` structure into the actual set of
* error items it represents and adds this directly into the provided `TrivialErrorBuilder`
*/
private [machine] def updateExpectedsAndGetSize(builder: TrivialErrorBuilder): Int = {
private [machine] def updateExpectedsAndGetSize(builder: TrivialErrorBuilder): Option[Int] = {
val hintCollector = builder.makeHintCollector
collect(hintCollector)
hintCollector.unexpectWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import scala.collection.mutable
import parsley.internal.machine.Context
import parsley.internal.machine.XAssert._

// TODO: Now PushHandlerAndCheck(label, false), so could be removed again!
private [internal] final class PushHandlerIterative(var label: Int) extends InstrWithLabel {
override def apply(ctx: Context): Unit = {
ensureRegularInstruction(ctx)
// This is used for iterative parsers, which must ensure that invalidated hints are invalided _now_
ctx.invalidateHints()
//ctx.invalidateHints() // FIXME: This has been removed because hint setting in updateCheckOffsetAndHints has been disabled, pending deep thought
ctx.pushCheck()
ctx.pushHandler(label)
ctx.inc()
Expand Down

0 comments on commit 15dce75

Please sign in to comment.