Skip to content

Commit

Permalink
Nim, Lua: fix sticking unary "not" operator to the number
Browse files Browse the repository at this point in the history
BaseTranslator does not insert space between operator and expression.
When expression is a number, "~<number>" and "!<number>" becomes "not<number>" which is an identifier

Fixes test (1):
```
[info]   - nim:~777 *** FAILED ***
[info]     "not[]777" was not equal to "not[ ]777" (TranslatorSpec.scala:183)
[info]     Analysis:
[info]     "not[]777" -> "not[ ]777"
```
  • Loading branch information
Mingun committed Oct 4, 2024
1 parent ab8666f commit 835eaed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class LuaTranslator(provider: TypeProvider, importList: ImportList) extends Base
case Ast.boolop.And => "and"
}
override def unaryOp(op: Ast.unaryop): String = op match {
case Ast.unaryop.Not => "not"
case Ast.unaryop.Not => "not "
case _ => super.unaryOp(op)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class NimTranslator(provider: TypeProvider, importList: ImportList) extends Base
// Members declared in io.kaitai.struct.translators.CommonMethods

override def unaryOp(op: Ast.unaryop): String = op match {
case Ast.unaryop.Invert => "not"
case Ast.unaryop.Invert => "not "
case Ast.unaryop.Minus => "-"
case Ast.unaryop.Not => "not"
case Ast.unaryop.Not => "not "
}

override def booleanOp(op: Ast.boolop): String = op match {
Expand Down

0 comments on commit 835eaed

Please sign in to comment.