Skip to content

Commit

Permalink
1) fixed string concatenation in the translator. 2) changed generated…
Browse files Browse the repository at this point in the history
… bool operators. 3) fixed a bug in strSubstring in the translator.
  • Loading branch information
sealmove committed Apr 4, 2020
1 parent 0ac3c25 commit ef7178c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base
override def arraySubscript(container: expr, idx: expr): String =
s"${translate(container)}[${translate(idx)}]"

override def strConcat(left: Ast.expr, right: Ast.expr): String = s"${translate(left)} & ${translate(right)}"
override def strConcat(left: Ast.expr, right: Ast.expr): String = "($" + s"${translate(left)} & " + "$" + s"${translate(right)})"

// Members declared in io.kaitai.struct.translators.CommonMethods

Expand All @@ -39,6 +39,11 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base
case Ast.unaryop.Not => "not"
}

override def booleanOp(op: Ast.boolop): String = op match {
case Ast.boolop.And => "and"
case Ast.boolop.Or => "or"
}

override def binOp(op: Ast.operator): String = {
op match {
case Ast.operator.Add => "+"
Expand Down Expand Up @@ -104,7 +109,7 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base
s"reversed(${translate(s)})"
}
override def strSubstring(s: expr, from: expr, to: expr): String =
s"${translate(s)}.substr(${translate(from)}, ${translate(to)})"
s"${translate(s)}.substr(${translate(from)}, ${translate(to)} - 1)"
override def strToInt(s: expr, base: expr): String =
s"${translate(s)}.parseInt(${translate(base)}"
s"${translate(s)}.parseInt(${translate(base)})"
}

0 comments on commit ef7178c

Please sign in to comment.