diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
commit | b6778be91900b8161e705dc2598ef7af86842b0b (patch) | |
tree | d15e8ec18a37eec212f50f1ace27714d7e7d4d34 /docs/examples/parsing/lambda/TestParser.scala | |
parent | ac6c76f26d884a94d0c9ff54f055d3f9ab750bac (diff) | |
download | scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.gz scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.bz2 scala-b6778be91900b8161e705dc2598ef7af86842b0b.zip |
Begone t1737...
Diffstat (limited to 'docs/examples/parsing/lambda/TestParser.scala')
-rw-r--r-- | docs/examples/parsing/lambda/TestParser.scala | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/examples/parsing/lambda/TestParser.scala b/docs/examples/parsing/lambda/TestParser.scala index 623b597337..d26589da1b 100644 --- a/docs/examples/parsing/lambda/TestParser.scala +++ b/docs/examples/parsing/lambda/TestParser.scala @@ -17,9 +17,9 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt lexical.reserved ++= List("unit", "let", "in", "if", "then", "else") lexical.delimiters ++= List("=>", "->", "==", "(", ")", "=", "\\", "+", "-", "*", "/") - + def name : Parser[Name] = ident ^^ Name - + // meaning of the arguments to the closure during subsequent iterations // (...(expr2 op1 expr1) ... op1 expr1) // ^a^^^ ^o^ ^b^^^ @@ -29,10 +29,10 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt def expr2 : Parser[Term] = chainl1(expr3, expr2, op2 ^^ {o => (a: Term, b: Term) => App(App(o, a), b)}) - + def expr3 : Parser[Term] = chainl1(expr4, expr3, op3 ^^ {o => (a: Term, b: Term) => App(App(o, a), b)}) - + def expr4 : Parser[Term] = ( "\\" ~> lambdas | ("let" ~> name) ~ ("=" ~> expr1) ~ ("in" ~> expr1) ^^ flatten3(Let) @@ -42,27 +42,27 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt def lambdas : Parser[Term] = name ~ ("->" ~> expr1 | lambdas) ^^ flatten2(Lam) - + def aexpr : Parser[Term] = ( numericLit ^^ (_.toInt) ^^ Lit | name ^^ Ref | "unit" ^^^ Unit() | "(" ~> expr1 <~ ")" ) - + def op1 : Parser[Term] = "==" ^^^ Ref(Name("==")) - + def op2 : Parser[Term] = ( "+" ^^^ Ref(Name("+")) | "-" ^^^ Ref(Name("-")) ) - + def op3 : Parser[Term] = ( "*" ^^^ Ref(Name("*")) | "/" ^^^ Ref(Name("/")) ) - + def parse(r: Reader[char]) : ParseResult[Term] = phrase(expr1)(new lexical.Scanner(r)) } |