Created
January 6, 2014 15:43
-
-
Save qharlie/8284650 to your computer and use it in GitHub Desktop.
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
/** | |
* 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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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