diff --git a/shared/src/main/scala/io/kaitai/struct/translators/NimTranslator.scala b/shared/src/main/scala/io/kaitai/struct/translators/NimTranslator.scala index e9972b407..ea5971dba 100644 --- a/shared/src/main/scala/io/kaitai/struct/translators/NimTranslator.scala +++ b/shared/src/main/scala/io/kaitai/struct/translators/NimTranslator.scala @@ -10,6 +10,15 @@ import io.kaitai.struct.format.{EnumSpec, Identifier} import io.kaitai.struct.languages.NimCompiler.{ksToNim, namespaced, camelCase} class NimTranslator(provider: TypeProvider, importList: ImportList) extends BaseTranslator(provider) { + override def genericBinOp(left: Ast.expr, op: Ast.operator, right: Ast.expr, extPrec: Int) = { + (detectType(left), detectType(right), op) match { + case (_: IntType, _: IntType, Ast.operator.Div) => + genericBinOpStr(left, op, "div", right, extPrec) + case _ => + super.genericBinOp(left, op, right, extPrec) + } + } + // Members declared in io.kaitai.struct.translators.BaseTranslator override def bytesToStr(bytesExpr: String, encoding: String): String = { s"""encode($bytesExpr, ${doStringLiteral(encoding)})""" @@ -62,7 +71,7 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base case Ast.operator.Add => "+" case Ast.operator.Sub => "-" case Ast.operator.Mult => "*" - case Ast.operator.Div => "div" + case Ast.operator.Div => "/" case Ast.operator.Mod => "%%%" case Ast.operator.BitAnd => "and" case Ast.operator.BitOr => "or"