Created
February 18, 2011 02:08
-
-
Save wolverian/833130 to your computer and use it in GitHub Desktop.
I'm confused about the Scala parser combinator libraries
This file contains 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 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