Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Forked from wolverian/Problem.scala
Created February 18, 2011 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrudolph/833412 to your computer and use it in GitHub Desktop.
Save jrudolph/833412 to your computer and use it in GitHub Desktop.
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
}
object MyModel extends SimpleAst {
object Parser extends TokenParsers {
type Tokens = SimpleLex
def parse = Num()
}
object PrettyPrinter {
def print(x: Exp) = 42
}
}
class Problem extends Application {
val parser = MyModel.Parser
val prettyPrinter = MyModel.PrettyPrinter
println(prettyPrinter.print(parser.parse))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment