Skip to content

Commit

Permalink
Merge branch 'backport/4.4' into wiki-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 authored Dec 24, 2023
2 parents 69d65e4 + fdd31c9 commit e8fc418
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion parsley/shared/src/main/scala/parsley/combinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ object combinator {
* @since 4.4.0
*/
def range[A](min: Int, max: Int)(p: Parsley[A]): Parsley[List[A]] = fresh(mutable.ListBuffer.empty[A]).persist { xs =>
count(min, max)((xs, p).zipped(_ += _).unsafe()) ~>
count(min, max)((xs, p).zipped(_ += _).impure) ~>
xs.map(_.toList)
}

Expand Down
2 changes: 1 addition & 1 deletion parsley/shared/src/main/scala/parsley/debug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object debug {
* @define debug This combinator allows this parser to be debugged by providing a trace through the execution.
*
* When this combinator is entered, it will print the name assigned to the parser,
* as well as the current currenting input context for a few characters on either side.
* as well as the current input context for a few characters on either side.
* This parser is then executed. If it succeeded, this combinator again reports the
* name along with "`Good`" and the input context. If it failed, it reports the name
* along with "`Bad`" and the input context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package parsley.internal.deepembedding

import scala.annotation.tailrec

import org.typelevel.scalaccompat.annotation.uncheckedVariance212

// Trampoline for CPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ package parsley.internal.errors
import parsley.XAssert._
import parsley.errors, errors.{ErrorBuilder, Token, TokenSpan}

private [internal] sealed abstract class ErrorItem
private [internal] sealed abstract class UnexpectItem extends ErrorItem {
private [internal] sealed abstract class UnexpectItem {
private [internal] def formatUnexpect(lexicalError: Boolean)(implicit builder: ErrorBuilder[_]): (builder.Item, TokenSpan)
private [internal] def higherPriority(other: UnexpectItem): Boolean
protected [errors] def lowerThanRaw(other: UnexpectRaw): Boolean
protected [errors] def lowerThanDesc(other: UnexpectDesc): Boolean
private [internal] def isFlexible: Boolean
private [internal] def widen(caret: Int): UnexpectItem
}
private [parsley] sealed trait ExpectItem extends ErrorItem {
private [parsley] sealed trait ExpectItem {
private [internal] def formatExpect(implicit builder: ErrorBuilder[_]): builder.Item
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private [internal] final class RelabelHints(labels: Iterable[String]) extends In
private [internal] final class RelabelErrorAndFail(labels: Iterable[String]) extends Instr {
override def apply(ctx: Context): Unit = {
ensureHandlerInstruction(ctx)
ctx.restoreHints()
//ctx.restoreHints() //FIXME: I'm not sure this was meant to be there in the first place
ctx.errs.error = ctx.useHints {
// only use the label if the error message is generated at the same offset
// as the check stack saved for the start of the `label` combinator.
Expand All @@ -45,7 +45,7 @@ private [internal] final class RelabelErrorAndFail(labels: Iterable[String]) ext
ctx.fail()
}
// $COVERAGE-OFF$
override def toString: String = s"ApplyError($labels)"
override def toString: String = s"RelabelErrorAndFail($labels)"
// $COVERAGE-ON$
}

Expand All @@ -62,6 +62,7 @@ private [internal] object HideHints extends Instr {
// $COVERAGE-ON$
}

// FIXME: Gigaparsec points out the hints aren't being used here, I believe they should be!
private [internal] object HideErrorAndFail extends Instr {
override def apply(ctx: Context): Unit = {
ensureHandlerInstruction(ctx)
Expand Down Expand Up @@ -119,6 +120,7 @@ private [internal] class ApplyReasonAndFail(reason: String) extends Instr {
private [internal] class AmendAndFail private (partial: Boolean) extends Instr {
override def apply(ctx: Context): Unit = {
ensureHandlerInstruction(ctx)
ctx.restoreHints() //TODO: verify this is ok; it feels more right than the restore on the labelling
ctx.handlers = ctx.handlers.tail
ctx.errs.error = ctx.errs.error.amend(partial, ctx.states.offset, ctx.states.line, ctx.states.col)
ctx.states = ctx.states.tail
Expand Down
4 changes: 2 additions & 2 deletions parsley/shared/src/main/scala/parsley/registers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ object registers {
def forYieldP_[A, B](init: Parsley[A], cond: =>Parsley[A => Boolean], step: =>Parsley[A => A])(body: Parsley[A] => Parsley[B]): Parsley[List[B]] = {
fresh(mutable.ListBuffer.empty[B]).persist { acc =>
forP_(init, cond, step) { x =>
(acc, body(x)).zipped(_ += _).unsafe() // we don't want this optimised out, it's a mutable operation in a resultless context
(acc, body(x)).zipped(_ += _).impure // we don't want this optimised out, it's a mutable operation in a resultless context
} ~> acc.map(_.toList)
}
}
Expand Down Expand Up @@ -514,7 +514,7 @@ object registers {
def forYieldP[A, B](init: Parsley[A], cond: =>Parsley[A => Boolean], step: =>Parsley[A => A])(body: =>Parsley[B]): Parsley[List[B]] = {
fresh(mutable.ListBuffer.empty[B]).persist { acc =>
forP(init, cond, step) {
(acc, body).zipped(_ += _).unsafe()
(acc, body).zipped(_ += _).impure
} ~> acc.map(_.toList)
}
}
Expand Down
2 changes: 1 addition & 1 deletion parsley/shared/src/main/scala/parsley/token/Lexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class Lexer(desc: descriptions.LexicalDesc, errConfig: errors.ErrorConfig) {
private [Lexer] val _integer = new SignedInteger(desc.numericDesc, _natural, errConfig)
private [Lexer] val _positiveReal = new UnsignedReal(desc.numericDesc, _natural, errConfig, generic)
private [Lexer] val _real = new SignedReal(desc.numericDesc, _positiveReal, errConfig)
private [Lexer] val _unsignedCombined = new UnsignedCombined(desc.numericDesc, _integer, _positiveReal, errConfig)
private [Lexer] val _unsignedCombined = new UnsignedCombined(desc.numericDesc, _natural, _positiveReal, errConfig)
private [Lexer] val _signedCombined = new SignedCombined(desc.numericDesc, _unsignedCombined, errConfig)

/** $natural
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ final case class EscapeDesc (escBegin: Char,
require(litAndSingle.isEmpty && litSingleAndMulti.isEmpty, "there can be no overlap between literals, singleMap, and multiMap")
litOrSingle | multiKeys
}
// TODO: ensure that at most one numeric sequence has an empty prefix
private [token] val escTrie = {
val escMap = multiMap ++ literals.map(c => s"$c" -> c.toInt) ++ singleMap.map {
case (k, v) => s"$k" -> v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private [token] final class ConcreteString(ends: Set[ScalaString], stringChar: S
}
// `content` is in a dropped position, so needs the unsafe to avoid the mutation
// TODO: this could be fixed better with registers and skipMany?
val content = valid(parsley.expr.infix.secretLeft1((sbReg.get, strChar).zipped(pf), strChar, pure(pf)).unsafe())
val content = valid(parsley.expr.infix.secretLeft1((sbReg.get, strChar).zipped(pf), strChar, pure(pf)).impure)
val terminal = string(terminalStr)
// terminal should be first, to allow for a jump table on the main choice
openLabel(allowsAllSpace, stringChar.isRaw)(terminal) *>
Expand Down
2 changes: 1 addition & 1 deletion parsley/shared/src/test/scala/parsley/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ErrorTests extends ParsleyTest {
}
}

it should "not replace hints if input is consumed" in {
it should "suppress hints even if input is consumed" in {
inside((many(digit).hide <* eof).parse("1e")) {
case Failure(TestError((1, 2), VanillaError(unex, exs, rs, 1))) =>
unex should contain (Raw("e"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EscapeSemanticPreservationSpec extends AnyPropSpec with ScalaCheckProperty
4 -> Gen.alphaNumStr,
1 -> Gen.numStr,
1 -> Gen.hexStr.map(s => s"x$s"),
1 -> Gen.stringOf(Gen.choose('0', '7')).map(s => s"b$s"),
1 -> Gen.stringOf(Gen.choose('0', '7')).map(s => s"o$s"),
1 -> Gen.stringOf(Gen.oneOf('0', '1')).map(s => s"b$s"),
).map(s => s"\\$s")

Expand Down

0 comments on commit e8fc418

Please sign in to comment.