diff options
Diffstat (limited to 'nimsuggest/sexp.nim')
-rw-r--r-- | nimsuggest/sexp.nim | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/nimsuggest/sexp.nim b/nimsuggest/sexp.nim index 654640309..03369ccb7 100644 --- a/nimsuggest/sexp.nim +++ b/nimsuggest/sexp.nim @@ -12,6 +12,11 @@ import hashes, strutils, lexbase, streams, unicode, macros +import std/private/decode_helpers + +when defined(nimPreviewSlimSystem): + import std/[assertions, formatfloat] + type SexpEventKind* = enum ## enumeration of all events that may occur when parsing sexpError, ## an error occurred during parsing @@ -113,14 +118,6 @@ proc errorMsgExpected*(my: SexpParser, e: string): string = ## other error messages result = "($1, $2) Error: $3" % [$getLine(my), $getColumn(my), e & " expected"] -proc handleHexChar(c: char, x: var int): bool = - result = true # Success - case c - of '0'..'9': x = (x shl 4) or (ord(c) - ord('0')) - of 'a'..'f': x = (x shl 4) or (ord(c) - ord('a') + 10) - of 'A'..'F': x = (x shl 4) or (ord(c) - ord('A') + 10) - else: result = false # error - proc parseString(my: var SexpParser): TTokKind = result = tkString var pos = my.bufpos + 1 @@ -290,41 +287,33 @@ proc raiseParseErr*(p: SexpParser, msg: string) {.noinline, noreturn.} = ## raises an `ESexpParsingError` exception. raise newException(SexpParsingError, errorMsgExpected(p, msg)) -proc newSString*(s: string): SexpNode {.procvar.}= +proc newSString*(s: string): SexpNode = ## Creates a new `SString SexpNode`. result = SexpNode(kind: SString, str: s) -proc newSStringMove(s: string): SexpNode = - result = SexpNode(kind: SString) - shallowCopy(result.str, s) - -proc newSInt*(n: BiggestInt): SexpNode {.procvar.} = +proc newSInt*(n: BiggestInt): SexpNode = ## Creates a new `SInt SexpNode`. result = SexpNode(kind: SInt, num: n) -proc newSFloat*(n: float): SexpNode {.procvar.} = +proc newSFloat*(n: float): SexpNode = ## Creates a new `SFloat SexpNode`. result = SexpNode(kind: SFloat, fnum: n) -proc newSNil*(): SexpNode {.procvar.} = +proc newSNil*(): SexpNode = ## Creates a new `SNil SexpNode`. result = SexpNode(kind: SNil) -proc newSCons*(car, cdr: SexpNode): SexpNode {.procvar.} = +proc newSCons*(car, cdr: SexpNode): SexpNode = ## Creates a new `SCons SexpNode` result = SexpNode(kind: SCons, car: car, cdr: cdr) -proc newSList*(): SexpNode {.procvar.} = +proc newSList*(): SexpNode = ## Creates a new `SList SexpNode` result = SexpNode(kind: SList, elems: @[]) -proc newSSymbol*(s: string): SexpNode {.procvar.} = +proc newSSymbol*(s: string): SexpNode = result = SexpNode(kind: SSymbol, symbol: s) -proc newSSymbolMove(s: string): SexpNode = - result = SexpNode(kind: SSymbol) - shallowCopy(result.symbol, s) - proc getStr*(n: SexpNode, default: string = ""): string = ## Retrieves the string value of a `SString SexpNode`. ## @@ -415,7 +404,7 @@ macro convertSexp*(x: untyped): untyped = ## `%` for every element. result = toSexp(x) -proc `==`* (a,b: SexpNode): bool = +func `==`* (a, b: SexpNode): bool = ## Check two nodes for equality if a.isNil: if b.isNil: return true @@ -602,8 +591,7 @@ proc parseSexp(p: var SexpParser): SexpNode = case p.tok of tkString: # we capture 'p.a' here, so we need to give it a fresh buffer afterwards: - result = newSStringMove(p.a) - p.a = "" + result = SexpNode(kind: SString, str: move p.a) discard getTok(p) of tkInt: result = newSInt(parseBiggestInt(p.a)) @@ -615,8 +603,7 @@ proc parseSexp(p: var SexpParser): SexpNode = result = newSNil() discard getTok(p) of tkSymbol: - result = newSSymbolMove(p.a) - p.a = "" + result = SexpNode(kind: SSymbol, symbol: move p.a) discard getTok(p) of tkParensLe: result = newSList() |