From bbb6ac2c3727e0e23ce3f8f08a223c9b86751bca Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Tue, 12 Sep 2023 14:16:05 +0100 Subject: [PATCH] Added the value `x` to the ErrorGen `adjustWidth`, allowing for more fine-grained control --- parsley/shared/src/main/scala/parsley/errors/ErrorGen.scala | 2 +- .../parsley/internal/machine/instructions/ErrorInstrs.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parsley/shared/src/main/scala/parsley/errors/ErrorGen.scala b/parsley/shared/src/main/scala/parsley/errors/ErrorGen.scala index 38319649a..82d1ff53a 100644 --- a/parsley/shared/src/main/scala/parsley/errors/ErrorGen.scala +++ b/parsley/shared/src/main/scala/parsley/errors/ErrorGen.scala @@ -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 diff --git a/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala b/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala index fca87a550..169ee97a2 100644 --- a/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala +++ b/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala @@ -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) @@ -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$