Skip to content

Instantly share code, notes, and snippets.

--- a/src/library/scala/util/parsing/combinator/Parsers.scala
+++ b/src/library/scala/util/parsing/combinator/Parsers.scala
@@ -17,31 +17,59 @@ import annotation.migration
/** `Parsers` is a component that ''provides'' generic parser combinators.
*
- * It ''requires'' the type of the elements these parsers should parse
+ * There are two abstract members that must be defined in order to
+ * produce parsers: the type `Elem` and
+ * [[scala.util.parsing.combinator.Parsers.Parser]]. There are helper
scala> def f(x: Any) = x match {
| case y: Double => println("Got a Double: "+x)
| case _ => println("Whatever")
| }
f: (x: Any)Unit
scala> f(true)
Whatever
scala> f(1)
@dcsobral
dcsobral / WordCount.scala
Created November 25, 2011 13:00
WordCount
// Based on Fantom's word count example here: http://blog.joda.org/2011/11/guide-to-evaluating-fantom.html
// I'm commenting the lines that need changing, and leaving a few of them uncommented,
// as they are the same
// class WordCount {
object WordCount {
// Void main(Str[] args) {
def main(args: Array[String]) {
if (args.size != 1) {
@dcsobral
dcsobral / gist:1419400
Created December 1, 2011 20:00
ant dist problem
dcs@ayanami:~/github/scala (new-master)$ ant dist
Buildfile: /home/dcs/github/scala/build.xml
[echo] Forking with JVM opts: -Xms1536M -Xmx1536M -Xss1M -XX:MaxPermSize=192M -XX:+UseParallelGC
dist:
[echo] Forking with JVM opts: -Xms1536M -Xmx1536M -Xss1M -XX:MaxPermSize=192M -XX:+UseParallelGC
strap.clean:
pack.clean:
quick.lib:
[mkdir] Created dir: /home/dcs/github/scala/build/quick/classes/library
[javac] Compiling 25 source files to /home/dcs/github/scala/build/quick/classes/library
[javac] Compiling 41 source files to /home/dcs/github/scala/build/quick/classes/library
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[scalacfork] Compiling 686 files to /home/dcs/github/scala/build/quick/classes/library
[scalacfork] error: error while loading Object, class file '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar(java/lang/Object.class)' is broken
[scalacfork] (167779022)
[scalacfork] one error found
@dcsobral
dcsobral / gist:1468858
Created December 12, 2011 20:05
aggregate error
[error] /home/dcs/tmp/my-benchmark/project/Build.scala:16: no `: _*' annotation allowed here
[error] (such annotations are only allowed in arguments to *-parameters)
[error] lazy val root = Project("root", file(".")) settings(sources := Nil) aggregate(benchProjects: _*)
[error] ^
[error] one error found
Relevant declaration:
override def projects = root +: benchProjects
lazy val root = (
Project("root", file("."), settings = Nil)
aggregate(benchProjects map Reference.projectToRef: _*)
//settings(sources in Compile := Nil) //, run in Compile <<= inputTask { (argTask: TaskKey[Seq[String]]) => argTask.map(_ => () )})
)
@dcsobral
dcsobral / gist:1473297
Created December 13, 2011 18:44
Build.scala
import sbt._
import Keys._
object MyBuild extends Build {
val distPath = "/home/dcs/github/scala/dists" // Set this to your environment
override def projects = root +: benchProjects
lazy val root = (
Project("root", file("."), settings = Nil)
@dcsobral
dcsobral / gist:1565038
Created January 5, 2012 12:20
Trailing commas in Scala
dcs@ayanami:~/github/GenRegex (master)$ ~/scala-2.7.7.final/bin/scala -deprecation
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> List(1, 2, 3,)
<console>:1: warning: Trailing commas have been deprecated
List(1, 2, 3,)
^
<console>:2: warning: Trailing commas have been deprecated
@dcsobral
dcsobral / hashmap-bench.scala
Created January 8, 2012 01:15 — forked from erikrozendaal/hashmap-bench.scala
Scala TreeMap benchmarks
import collection.mutable.ArrayBuffer
import collection.immutable.HashMap
object HashMapTest {
val random = new util.Random(1234)
def time(block: => Unit): Double = {
val start = System.nanoTime()
block