Skip to content

Commit

Permalink
Added the value x to the ErrorGen adjustWidth, allowing for more …
Browse files Browse the repository at this point in the history
…fine-grained control
  • Loading branch information
j-mie6 committed Sep 12, 2023
1 parent 9bdf4e8 commit bbb6ac2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sealed abstract class ErrorGen[-A] {
final def parser: Parsley[((A, Int)) => Nothing] = new Parsley(internal)
private [errors] def internal: LazyParsley[((A, Int)) => Nothing]

def adjustWidth(width: Int): Int = width
def adjustWidth(@unused x: A, width: Int): Int = width
}
class VanillaGen[-A] extends ErrorGen[A] {
def unexpected(@unused x: A): UnexpectedItem = UnexpectedItem.Empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private [internal] final class VanillaGen[A](gen: parsley.errors.VanillaGen[A])
val (x, caretWidth) = ctx.stack.pop[(A, Int)]()
val unex = gen.unexpected(x)
val reason = gen.reason(x)
val err = unex.makeError(ctx.offset, ctx.line, ctx.col, gen.adjustWidth(caretWidth))
val err = unex.makeError(ctx.offset, ctx.line, ctx.col, gen.adjustWidth(x, caretWidth))
// Sorry, it's faster :(
if (reason.isDefined) ctx.fail(err.withReason(reason.get))
else ctx.fail(err)
Expand All @@ -218,7 +218,7 @@ private [internal] final class SpecialisedGen[A](gen: parsley.errors.Specialised
ensureRegularInstruction(ctx)
// stack will have an (A, Int) pair on it
val (x, caretWidth) = ctx.stack.pop[(A, Int)]()
ctx.failWithMessage(new RigidCaret(gen.adjustWidth(caretWidth)), gen.messages(x): _*)
ctx.failWithMessage(new RigidCaret(gen.adjustWidth(x, caretWidth)), gen.messages(x): _*)
}

// $COVERAGE-OFF$
Expand Down

0 comments on commit bbb6ac2

Please sign in to comment.