Skip to content

Commit

Permalink
fix: moved ManyUntil.Stop into instructions package
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 20, 2025
1 parent 59ab781 commit ed29ad6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 2 additions & 6 deletions parsley/shared/src/main/scala/parsley/combinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,12 @@ private [parsley] trait combinator {
*/
final def manyTill[A](p: Parsley[A], end: Parsley[_]): Parsley[List[A]] = manyTill(p, end, List)
private [parsley] final def manyTill[A, C](p: Parsley[A], end: Parsley[_], factory: Factory[A, C]): Parsley[C] = {
new Parsley(new frontend.ManyTill((end.as(ManyUntil.Stop).ut() |: p: Parsley[Any]).internal, factory))
new Parsley(new frontend.ManyTill((end.as(parsley.internal.machine.instructions.ManyUntil.Stop).ut() |: p: Parsley[Any]).internal, factory))
}

// TODO: find a way to make this redundant
private [parsley] final def skipManyUntil(p: Parsley[_], end: Parsley[_]): Parsley[Unit] = {
new Parsley(new frontend.SkipManyUntil((end.as(ManyUntil.Stop).ut() |: p.void.ut(): Parsley[Any]).internal))
}

private [parsley] object ManyUntil {
object Stop
new Parsley(new frontend.SkipManyUntil((end.as(parsley.internal.machine.instructions.ManyUntil.Stop).ut() |: p.void.ut(): Parsley[Any]).internal))
}

/** This combinator repeatedly parses a given parser '''one''' or more times, until the `end` parser succeeds, collecting the results into a list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private [internal] final class ManyUntil(var label: Int) extends InstrWithLabel
override def apply(ctx: Context): Unit = {
ensureRegularInstruction(ctx)
ctx.stack.upop() match {
case parsley.combinator.ManyUntil.Stop => ctx.exchangeAndContinue(ctx.stack.peek[mutable.Builder[Any, Any]].result())
case ManyUntil.Stop => ctx.exchangeAndContinue(ctx.stack.peek[mutable.Builder[Any, Any]].result())
case x =>
ctx.stack.peek[mutable.Builder[Any, Any]] += x
ctx.pc = label
Expand All @@ -227,12 +227,15 @@ private [internal] final class ManyUntil(var label: Int) extends InstrWithLabel
override def toString: String = s"ManyUntil($label)"
// $COVERAGE-ON$
}
private [parsley] object ManyUntil {
object Stop
}

private [internal] final class SkipManyUntil(var label: Int) extends InstrWithLabel {
override def apply(ctx: Context): Unit = {
ensureRegularInstruction(ctx)
ctx.stack.upop() match {
case parsley.combinator.ManyUntil.Stop => ctx.inc()
case ManyUntil.Stop => ctx.inc()
case _ => ctx.pc = label
}
}
Expand Down

0 comments on commit ed29ad6

Please sign in to comment.