Skip to content

Commit

Permalink
Update generators
Browse files Browse the repository at this point in the history
  • Loading branch information
sake92 committed Apr 15, 2024
1 parent c0eeaa7 commit 3173410
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions editor/src/main/scala/dev/sacode/flowrun/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sacode.flowrun

import scala.util.boundary, boundary.break
import scala.util.Try
import scala.util.Success
import scala.util.Failure
Expand Down Expand Up @@ -47,7 +48,8 @@ object DomUtils {
def isTouchDevice: Boolean =
dom.window.matchMedia("(pointer: coarse)").matches

def getNearestSvgNode(event: dom.MouseEvent): (String, dom.svg.G) = {
def getNearestSvgNode(event: dom.MouseEvent): (String, dom.svg.G) = boundary {

getSvgNode(event.target).getOrElse {
for (i <- 1 to 48) { // search around mouse click for nearby edges
val nearNodes = List(
Expand All @@ -57,7 +59,7 @@ object DomUtils {
dom.document.elementFromPoint(event.clientX, event.clientY - i)
).flatMap(getSvgNode)
val maybeNode = nearNodes.headOption
if maybeNode.isDefined && maybeNode.get._1 == "EDGE" then return maybeNode.get
if maybeNode.isDefined && maybeNode.get._1 == "EDGE" then break(maybeNode.get)
}
("", null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CPlusPlusGenerator(val programAst: Program) extends CodeGenerator {
case RealToInteger => s"(int)${argOpt(0)}"
case StringToInteger =>
s"""try { Convert.ToInt32(${argOpt(0)}) } catch (FormatException) { 0 }"""
case ReadInput => "cin >> dummy"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class CSharpGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}.charAt(${argOpt(1)})"
case RealToInteger => s"(int)${argOpt(0)}"
case StringToInteger => s"Convert.ToInt32(${argOpt(0)})"
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class GolangGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}.charAt(${argOpt(1)})"
case RealToInteger => s"${argOpt(0)}.toInt"
case StringToInteger => s"strconv.Itoa(${argOpt(0)})"
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class JavaGenerator(val programAst: Program) extends CodeGenerator {
case RealToInteger => s"(int)${argOpt(0)}"
case StringToInteger =>
s"""Integer.parseInt(${argOpt(0)})"""
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class JavascriptGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}.charAt(${argOpt(1)})"
case RealToInteger => argOpt(0) // ??
case StringToInteger => s"parseInt(${argOpt(0)})"
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class KotlinGenerator(val programAst: Program) extends CodeGenerator {
case RealToInteger => s"(int)${argOpt(0)}"
case StringToInteger =>
s"""try { Integer.parseInt(${argOpt(0)}) } catch (NumberFormatException e) { 0 }"""
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class PhpGenerator(val programAst: Program) extends CodeGenerator {
case RealToInteger => argOpt(0) // ??
case StringToInteger =>
s""" intval(${argOpt(0)}) """.trim
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class PythonGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}[${argOpt(1)}]"
case RealToInteger => s"int(${argOpt(0)})"
case StringToInteger => s"int(${argOpt(0)})"
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class RubyGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}.charAt(${argOpt(1)})"
case RealToInteger => s"${argOpt(0)}.toInt"
case StringToInteger => s"${argOpt(0)}.to_i"
case ReadInput => "Console.ReadLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class ScalaGenerator(val programAst: Program) extends CodeGenerator {
case CharAt => s"${argOpt(0)}.charAt(${argOpt(1)})"
case RealToInteger => s"${argOpt(0)}.toInt"
case StringToInteger => s"${argOpt(0)}.toInt"
case ReadInput => "StdIn.readLine()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class SwiftGenerator(val programAst: Program) extends CodeGenerator {
s"""try Int(${argOpt(0)})! catch {
| case _: NumberFormatException => 0
|}""".stripMargin
case ReadInput => "Console.ReadLine()"

}
}

Expand Down

0 comments on commit 3173410

Please sign in to comment.