Skip to content

Instantly share code, notes, and snippets.

@wolverian
Created February 18, 2011 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wolverian/833130 to your computer and use it in GitHub Desktop.
Save wolverian/833130 to your computer and use it in GitHub Desktop.
I'm confused about the Scala parser combinator libraries
package wolv.parserlibproblem
import util.parsing.ast.AbstractSyntax
import util.parsing.combinator.syntactical.TokenParsers
import util.parsing.combinator.lexical.Lexical
import util.parsing.combinator.token.Tokens
trait SimpleTokens extends Tokens {
case class Foo extends Token
case class Bar extends Token
}
class SimpleLex extends Lexical with SimpleTokens {
}
trait SimpleAst extends AbstractSyntax {
sealed trait Exp extends Element
case class Num() extends Exp
case class Str() extends Exp
}
class Parser extends TokenParsers with SimpleAst {
type Tokens = SimpleLex
def parse = Num()
}
class PrettyPrinter extends SimpleAst {
def print(x: Exp) = 42
}
class Problem extends Application {
val parser = new Parser
val prettyPrinter = new PrettyPrinter
println(prettyPrinter.print(parser.parse))
}
/*
Problem.scala:38: error: type mismatch;
[INFO] found : Problem.this.parser.Num
[INFO] required: Problem.this.prettyPrinter.ast.Exp
[INFO] println(prettyPrinter.print(parser.parse))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment