This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mada.vec | |
| /* | |
| private[mada] object TriplesVector { | |
| def apply[A](from: Vector[Vector.Triple[A]]): Vector[Vector[A]] = from match { | |
| case from: VectorTriples[_] => from.from // conversion fusion | |
| case _ => new TriplesVector(from) | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mada.vec | |
| private[mada] object TripleVector { | |
| def apply[A](v: Vector.Triple[A]): Vector[A] = v._1(v._2, v._3) | |
| } | |
| private[mada] object VectorTriple { | |
| def apply[A](v: Vector[A]): Vector.Triple[A] = (v, v.start, v.end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright Shunsuke Sogame 2008-2009. | |
| // Distributed under the terms of an MIT-style license. | |
| // See: "Packrat Parsers Can Support Left Recursion" | |
| package mada.peg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright Shunsuke Sogame 2008-2009. | |
| // Distributed under the terms of an MIT-style license. | |
| // See: "Packrat Parsers Can Support Left Recursion" | |
| package madatest.peg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] object Fold { | |
| def apply[A](v: Vector[A], z: A, op: (A, A) => A): A = { | |
| (Vector.single(z) ++ v).reduce(op) | |
| } | |
| } | |
| private[mada] object Folder { | |
| def apply[A](v: Vector[A], z: A, op: (A, A) => A): Vector[A] = { | |
| (Vector.single(z) ++ v).reducer(op) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] object Memoize { | |
| def apply[A](p: Peg[A]): Peg[A] = new MemoizePeg(p) | |
| } | |
| private[mada] class MemoizePeg[A](override val self: Peg[A]) extends PegProxy[A] { | |
| val memoTable = new scala.collection.jcl.HashMap[TripleKey[A], Int] | |
| override def parse(v: Vector[A], start: Int, end: Int) = { | |
| val key = new TripleKey(v, start, end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] case class TripleKey[A](v: Vector[A], start: Int, end: Int) { | |
| override def equals(that: Any) = that match { | |
| case that: TripleKey[_] => (v eq that.v) && (start == that.start) && (end == that.end) | |
| case _ => false | |
| } | |
| override def hashCode = { | |
| HashCode.ofRef(v) + HashCode.ofInt(start) * 7 + HashCode.ofInt(end) * 41 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] class StarPeg[A](p: Peg[A]) extends Reluctant[A] { | |
| override def parse(v: Vector[A], start: Int, end: Int): Int = { | |
| // StarUntil(p, !p) would include unneeded parsing. | |
| var cur = start | |
| while (cur != end) { | |
| val next = p.parse(v, cur, end) | |
| if (next == Peg.FAILURE) { | |
| return cur | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] class PlusPeg[A](p: Peg[A]) extends PegProxy[A] with Reluctant[A] { | |
| override val self = p >> p.* | |
| override def before(that: Peg[A]) = p >> (p.* before that) | |
| override def until(that: Peg[A]) = p >> (p.* until that) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private[mada] class OptPeg[A](p: Peg[A]) extends PegProxy[A] with Reluctant[A] { | |
| override val self = p | Peg.eps[A] | |
| override def before(that: Peg[A]) = (p >> ~that) | ~that | |
| override def until(that: Peg[A]) = (p >> that) | that | |
| } |
OlderNewer