Created
January 19, 2012 20:25
-
-
Save systay/1642357 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
def term: Parser[Expression] = factor ~ rep("*" ~ factor | "/" ~ factor) ^^ { | |
case head ~ rest => { | |
var result = head | |
rest.foreach { | |
case "*" ~ f => result = Multiply(result,f) | |
case "/" ~ f => result = Divide(result,f) | |
} | |
result | |
} | |
} | |
def expression: Parser[Expression] = term ~ rep( "+" ~ term | "-" ~ term) ^^ { | |
case head ~ rest => { | |
var result = head | |
rest.foreach { | |
case "+" ~ f => result = Add(result, f) | |
case "-" ~ f => result = Subtract(result, f) | |
} | |
result | |
} | |
} | |
def factor: Parser[Expression] = | |
( ignoreCase("true") ^^ (x => Literal(true)) | |
| ignoreCase("false") ^^ (x => Literal(false)) | |
| extract | |
| function | |
| identity~>parens(expression | entity)~>failure("unknown function") | |
| coalesceFunc | |
| nullableProperty | |
| property | |
| string ^^ (x => Literal(x)) | |
| number ^^ (x => Literal(x.toDouble)) | |
| parameter | |
| entity | |
| parens(expression) | |
| failure("illegal start of value") ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment