Skip to content

Instantly share code, notes, and snippets.

@qharlie
Created January 6, 2014 15:43
Show Gist options
  • Save qharlie/8284650 to your computer and use it in GitHub Desktop.
Save qharlie/8284650 to your computer and use it in GitHub Desktop.
/**
* Created with IntelliJ IDEA.
* User: q
* Date: 1/3/14
* Time: 4:04 PM
* To change this template use File | Settings | File Templates.
*/
import scala.util.parsing.combinator._
class ProgramAST;
class ModelAST;
class ModelMemberAST;
class ModelCombinator extends JavaTokenParsers {
def program: Parser[ProgramAST] = rep(model) ^^ new ProgramAST()
def model: Parser[Any] = "model" ~ ident ~ "{" ~ rep(member) ~ "}"
def member: Parser[Any] = ident ~ ":" ~ ident ~ relationNode.?
def relationNode: Parser[Any] = "@" ~ ("eager" | "lazy") ~ relation.? ~ ";"
def relationMember: Parser[Any] = "N" | "1"
def relation: Parser[Any] = "[" ~ relationMember ~ "-" ~ relationMember ~ "]"
}
object Main extends ModelCombinator {
def main(args: Array[String]) {
val result = parseAll(program, "model User { name : String } ")
// println(s"Parsed $result")
}
}
@qharlie
Copy link
Author

qharlie commented Jan 6, 2014

scala: type mismatch;
found : ProgramAST
required: List[Any] => ProgramAST
def program: Parser[ProgramAST] = rep(model) ^^ new ProgramAST()
^

I'm not sure how to read this error, but its always the same no matter what I return from program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment