summaryrefslogtreecommitdiff
path: root/docs/examples/parsing/lambda/TestParser.scala
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/parsing/lambda/TestParser.scala')
-rw-r--r--docs/examples/parsing/lambda/TestParser.scala18
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))
}