diff --git a/src/types/methods.nim b/src/types/methods.nim index bb7f0de..f61e32b 100644 --- a/src/types/methods.nim +++ b/src/types/methods.nim @@ -29,10 +29,11 @@ import ../config import ../memory import ../meta/opcode import arraylist -when DEBUG_TRACE_ALLOCATION: - import strformat +import exception +import strformat import parseutils +import strutils proc typeName*(self: ptr Obj): string = @@ -433,10 +434,16 @@ proc objAs*(self: ptr Obj, other: ObjectType): returnType = of ObjectType.Integer: case self.kind: of ObjectType.String: + var str = cast[ptr String](self).toStr() + for c in str: + if not c.isDigit(): + result.kind = returnTypes.Exception + result.result = newTypeError(&"invalid literal for int: '{str}'") + return var intVal: int - discard parseInt(cast[ptr String](self).toStr(), intVal) + discard parseInt(str, intVal) result.result = intVal.asInt() - of ObjectType.Float: + of ObjectType.Float: var floatVal: float64 discard (parseFloat(cast[ptr Float](self).stringify(), floatVal)) result.result = int(floatVal).asInt() @@ -447,6 +454,22 @@ proc objAs*(self: ptr Obj, other: ObjectType): returnType = of ObjectType.Float: case self.kind: of ObjectType.String: + var str = cast[ptr String](self).toStr() + var seenDot = false + for c in str: + if not c.isDigit(): + if c == '.': + if seenDot: + result.kind = returnTypes.Exception + result.result = newTypeError(&"invalid literal for float: '{str}'") + return + else: + seenDot = true + continue + else: + result.kind = returnTypes.Exception + result.result = newTypeError(&"invalid literal for float: '{str}'") + return var floatVal: float64 discard parseFloat(cast[ptr String](self).toStr(), floatVal) result.result = floatVal.asFloat() diff --git a/tests/localization.nim b/tests/localization.nim index 9e391df..707da20 100644 --- a/tests/localization.nim +++ b/tests/localization.nim @@ -18,10 +18,10 @@ const language = 1 when language == 1: const aa* = "ICBfX18gICAgX19fICAgX19fICBfX18gIF9fXyAgX19fICAgICAgIF9fICAgICAgX18gIF9fXyAgICBfX18gICBfX18gIF9fXyAgX19fICBfX18gCiAvIF8gXCAgLyBfIFwgfCBfIFwvIF9ffHxfIF98fCBfX3wgICAgICBcIFwgICAgLyAvIC8gXyBcICAvIF8gXCB8IF8gXC8gX198fF8gX3x8IF9ffAp8IChfKSB8fCAoXykgfHwgIF8vXF9fIFwgfCB8IHwgX3wgICAgICAgIFwgXC9cLyAvIHwgKF8pIHx8IChfKSB8fCAgXy9cX18gXCB8IHwgfCBffCAKIFxfX18vICBcX19fLyB8X3wgIHxfX18vfF9fX3x8X19ffCAgICAgICAgXF8vXF8vICAgXF9fXy8gIFxfX18vIHxffCAgfF9fXy98X19ffHxfX198Cgo=" - const bb* = "VXd1IFdlIG1hZGUgYSBmKmNreSB3dWNreSEhIEEgd2l0dGxlIGYqY2tvIGJvaW5nbyE=" const cc* = "VGhlIGNvZGUgbW9ua2V5cyBhdCBvdXIgaGVhZHF1YXJ0ZXJzIGFyZSB3b3JraW5nIFZFV1kgSEFXRCB0byBmaXggdGhpcyEK" + proc getCurrentExceptionMessage*: string = when language == 1: echo decode aa diff --git a/tests/testmarkup.md b/tests/testmarkup.md index f5129c3..528471c 100644 --- a/tests/testmarkup.md +++ b/tests/testmarkup.md @@ -42,7 +42,7 @@ Modelines also have to be closed by a ']' character on the end of this line. These lines may not contain whitespace before the opening '[' or "//[" nor after then ending ']' characters. Inside the brackets, letters (case -insensitive), numbers, underscores and dashes form\ +insensitive), numbers, underscores and dashes form a name describing what the modeline does. ``` @@ -138,7 +138,7 @@ There are two kinds of source modes, raw and mixed. Mixed source mode can be entered if the detail `mixed` is specified. Raw source mode can be entered if the detail `raw` is specified. When no detail is specified, -raw source mode is entered. +raw source mode is assumed. In raw source mode, all lines in the mode are appended as they are to the JAPL source. In mixed