From db364f2adc1d58c3ad3ddbe1b34e2021f4258b9f Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 21 Oct 2015 21:09:44 +0300 Subject: [PATCH] Fix bug in Scala calculator --- .../src/main/scala/org/teavm/samples/scala/Calculator.scala | 2 +- .../src/main/scala/org/teavm/samples/scala/Client.scala | 6 ++++-- .../src/main/scala/org/teavm/samples/scala/Grammar.scala | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/samples/scala/src/main/scala/org/teavm/samples/scala/Calculator.scala b/samples/scala/src/main/scala/org/teavm/samples/scala/Calculator.scala index 9606b60c8..b565ad75a 100644 --- a/samples/scala/src/main/scala/org/teavm/samples/scala/Calculator.scala +++ b/samples/scala/src/main/scala/org/teavm/samples/scala/Calculator.scala @@ -7,7 +7,7 @@ object Calculator { case Add(a, b) => eval(a) + eval(b) case Subtract(a, b) => eval(a) - eval(b) case Multiply(a, b) => eval(a) * eval(b) - case Divide(a, b) => eval(a) * eval(b) + case Divide(a, b) => eval(a) / eval(b) case Negate(n) => -eval(n) case Number(v) => v } diff --git a/samples/scala/src/main/scala/org/teavm/samples/scala/Client.scala b/samples/scala/src/main/scala/org/teavm/samples/scala/Client.scala index 66c0f6aef..ecb4faa25 100644 --- a/samples/scala/src/main/scala/org/teavm/samples/scala/Client.scala +++ b/samples/scala/src/main/scala/org/teavm/samples/scala/Client.scala @@ -19,8 +19,10 @@ object Client { case (None, _) => Window.alert("Error parsing expression"); case (Some(x), Nil) => { resultList.insertBefore(doc.createElement("div", (elem : HTMLElement) => { - elem.withChild("span").withAttr("class", "plan").withText(print(x) + " = ") - elem.withChild("span").withAttr("class", "result").withText(eval(x).toString) + elem.withChild("span", (child : HTMLElement) => + child.withAttr("class", "plan").withText(print(x) + " = ")) + elem.withChild("span", (child : HTMLElement) => + child.withAttr("class", "result").withText(eval(x).toString)) }), resultList.getFirstChild) } case (_, err) => Window.alert("Error parsing expression: " + err); diff --git a/samples/scala/src/main/scala/org/teavm/samples/scala/Grammar.scala b/samples/scala/src/main/scala/org/teavm/samples/scala/Grammar.scala index 4f926950c..22a9b286b 100644 --- a/samples/scala/src/main/scala/org/teavm/samples/scala/Grammar.scala +++ b/samples/scala/src/main/scala/org/teavm/samples/scala/Grammar.scala @@ -47,7 +47,7 @@ object Rule { } rule(chars => { val (result, rem) = iter(chars) - (Some(result.reverse), rem) + (Some(result), rem) }) } def firstOf[T](first : Rule[T], second : => Rule[T]) : Rule[T] = {