From 69e372beeaa4c1aa306efb13237bf274a33a1f05 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sat, 20 Jun 2020 13:52:01 -0500 Subject: [PATCH] Improve octal fix --- nimterop/build.nim | 5 ++++- nimterop/build/nimconf.nim | 3 ++- nimterop/toastlib/exprparser.nim | 22 ++++++++++------------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/nimterop/build.nim b/nimterop/build.nim index 99adeca..0754615 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -1,4 +1,7 @@ -import hashes, macros, osproc, sets, strformat, strutils, tables +import hashes, osproc, sets, strformat, strutils + +when not defined(TOAST): + import macros, tables import os except findExe, sleep diff --git a/nimterop/build/nimconf.nim b/nimterop/build/nimconf.nim index 98fc8fe..3ba5ed0 100644 --- a/nimterop/build/nimconf.nim +++ b/nimterop/build/nimconf.nim @@ -1,4 +1,4 @@ -import json, macros, os, osproc, sets, strformat, strutils +import json, os, osproc, sets, strformat, strutils when nimvm: when (NimMajor, NimMinor, NimPatch) >= (1, 2, 0): @@ -55,6 +55,7 @@ proc getProjectDir*(): string = result = querySetting(projectFull).parentDir() else: # Get from `macros` + import macros result = getProjectPath() else: discard diff --git a/nimterop/toastlib/exprparser.nim b/nimterop/toastlib/exprparser.nim index dc9f97e..28b49d3 100644 --- a/nimterop/toastlib/exprparser.nim +++ b/nimterop/toastlib/exprparser.nim @@ -140,15 +140,16 @@ proc getIntNode(number, suffix: string): PNode {.inline.} = var val: BiggestInt flags: TNodeFlags - if number.startsWith("0X") or number.startsWith("0x"): - val = parseHexInt(number) - flags = {nfBase16} - elif number.startsWith("0B") or number.startsWith("0b"): - val = parseBinInt(number) - flags = {nfBase2} - elif number.startsWith("0O") or number.startsWith("0o"): - val = parseOctInt(number) - flags = {nfBase8} + if number.len > 1 and number[0] == '0': + if number[1] in ['x', 'X']: + val = parseHexInt(number) + flags = {nfBase16} + elif number[1] in ['b', 'B']: + val = parseBinInt(number) + flags = {nfBase2} + else: + val = parseOctInt(number) + flags = {nfBase8} else: val = parseInt(number) @@ -201,9 +202,6 @@ proc processNumberLiteral(gState: State, node: TSNode): PNode = if number.startsWith("-"): number = number[1 ..< number.len] prefix = "-" - if number.len > 1 and number[0] == '0' and number[1] notin ['x', 'X']: - # Octal 0123 - number = "0o" & number[1 .. ^1] if tripleEndings.any(proc (s: string): bool = number.endsWith(s)): suffix = number[^3 .. ^1] number = number[0 ..< ^3]