Skip to content

Instantly share code, notes, and snippets.

@okomok
okomok / using maven-repo
Created October 17, 2010 07:24
using maven-repo
// Copyright Shunsuke Sogame 2008-2010.
// Distributed under the terms of an MIT-style license.
import sbt._
class HelloSbt(info: ProjectInfo) extends DefaultProject(info) {
override def compileOptions = Seq(Deprecation, Unchecked/*, ExplainTypes*/) ++ compileOptions("-Yrecursion", "50") ++ super.compileOptions
@okomok
okomok / gist:102427
Created April 27, 2009 10:24
forwarding
trait Func0 {
type A1 <: Any
type A2 <: Any
type apply2[x <: A1, y <: A2]
}
type foo[f <: Func0 { type A1 >: String; type A2 >: Any }] = f#apply2[String, Any]
trait f extends Func0 {
type A1 = String
type A2 = Any
@okomok
okomok / gist:80658
Created March 17, 2009 17:08
wrong mulitpass
// Copyright Shunsuke Sogame 2008-2009.
// Distributed under the terms of an MIT-style license.
package mada.iter
/**
@okomok
okomok / gist:61515
Created February 10, 2009 18:22
old opt
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
}
@okomok
okomok / gist:61514
Created February 10, 2009 18:22
old plus
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)
}
@okomok
okomok / gist:61513
Created February 10, 2009 18:22
old star
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
}
@okomok
okomok / gist:58249
Created February 4, 2009 18:17
rejected triple key
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
}
}
@okomok
okomok / gist:58241
Created February 4, 2009 18:08
rejected memoize
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)
@okomok
okomok / gist:55884
Created February 1, 2009 15:49
fold using reduce
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)
@okomok
okomok / gist:54936
Created January 30, 2009 04:12
LRule test
// Copyright Shunsuke Sogame 2008-2009.
// Distributed under the terms of an MIT-style license.
// See: "Packrat Parsers Can Support Left Recursion"
package madatest.peg