SexpEventKind = enum sexpError, ## an error occurred during parsing sexpEof, ## end of file reached sexpString, ## a string literal sexpSymbol, ## a symbol sexpInt, ## an integer literal sexpFloat, ## a float literal sexpNil, ## the value ``nil`` sexpDot, ## the dot to separate car/cdr sexpListStart, ## start of a list: the ``(`` token sexpListEnd ## end of a list: the ``)`` token
SexpError = enum errNone, ## no error errInvalidToken, ## invalid token errParensRiExpected, ## ``)`` expected errQuoteExpected, ## ``"`` expected errEofExpected ## EOF expected
SexpParser = object of BaseLexer a: string tok: TTokKind kind: SexpEventKind err: SexpError
SexpNodeKind = enum SNil, SInt, SFloat, SString, SSymbol, SList, SCons
SexpNode = ref SexpNodeObj
SexpNodeObj {...}{.acyclic.} = object case kind*: SexpNodeKind of SString: str*: string of SSymbol: symbol*: string of SInt: num*: BiggestInt of SFloat: fnum*: float of SList: elems*: seq[SexpNode] of SCons: car: SexpNode cdr: SexpNode of SNil: nil
SexpParsingError = object of ValueError
proc close(my: var SexpParser) {...}{.inline, raises: [Exception], tags: [].}
proc str(my: SexpParser): string {...}{.inline, raises: [], tags: [].}
sexpInt
, sexpFloat
, sexpString
proc getInt(my: SexpParser): BiggestInt {...}{.inline, raises: [ValueError], tags: [].}
sexpInt
proc getFloat(my: SexpParser): float {...}{.inline, raises: [ValueError], tags: [].}
sexpFloat
proc kind(my: SexpParser): SexpEventKind {...}{.inline, raises: [], tags: [].}
proc getColumn(my: SexpParser): int {...}{.inline, raises: [], tags: [].}
proc getLine(my: SexpParser): int {...}{.inline, raises: [], tags: [].}
proc errorMsg(my: SexpParser): string {...}{.raises: [ValueError], tags: [].}
sexpError
proc errorMsgExpected(my: SexpParser; e: string): string {...}{.raises: [ValueError], tags: [].}
proc raiseParseErr(p: SexpParser; msg: string) {...}{.noinline, noreturn, raises: [SexpParsingError, ValueError], tags: [].}
proc newSString(s: string): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSInt(n: BiggestInt): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSFloat(n: float): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSNil(): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSCons(car, cdr: SexpNode): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSList(): SexpNode {...}{.procvar, raises: [], tags: [].}
proc newSSymbol(s: string): SexpNode {...}{.procvar, raises: [], tags: [].}
proc getStr(n: SexpNode; default: string = ""): string {...}{.raises: [], tags: [].}
Retrieves the string value of a SString SexpNode.
Returns default
if n
is not a SString
.
proc getNum(n: SexpNode; default: BiggestInt = 0): BiggestInt {...}{.raises: [], tags: [].}
Retrieves the int value of a SInt SexpNode.
Returns default
if n
is not a SInt
.
proc getFNum(n: SexpNode; default: float = 0.0): float {...}{.raises: [], tags: [].}
Retrieves the float value of a SFloat SexpNode.
Returns default
if n
is not a SFloat
.
proc getSymbol(n: SexpNode; default: string = ""): string {...}{.raises: [], tags: [].}
Retrieves the int value of a SList SexpNode.
Returns default
if n
is not a SList
.
proc getElems(n: SexpNode; default: seq[SexpNode] = @[]): seq[SexpNode] {...}{.raises: [], tags: [].}
Retrieves the int value of a SList SexpNode.
Returns default
if n
is not a SList
.
proc getCons(n: SexpNode; defaults: Cons = (newSNil(), newSNil())): Cons {...}{.raises: [], tags: [].}
Retrieves the cons value of a SList SexpNode.
Returns default
if n
is not a SList
.
proc sexp(s: string): SexpNode {...}{.raises: [], tags: [].}
proc sexp(n: BiggestInt): SexpNode {...}{.raises: [], tags: [].}
proc sexp(n: float): SexpNode {...}{.raises: [], tags: [].}
proc sexp(b: bool): SexpNode {...}{.raises: [], tags: [].}
proc sexp(elements: openArray[SexpNode]): SexpNode {...}{.raises: [], tags: [].}
proc sexp(s: SexpNode): SexpNode {...}{.raises: [], tags: [].}
proc `==`(a, b: SexpNode): bool {...}{.raises: [], tags: [].}
proc hash(n: SexpNode): Hash {...}{.raises: [], tags: [].}
proc len(n: SexpNode): int {...}{.raises: [], tags: [].}
proc `[]`(node: SexpNode; index: int): SexpNode {...}{.raises: [], tags: [].}
proc add(father, child: SexpNode) {...}{.raises: [], tags: [].}
proc escapeJson(s: string): string {...}{.raises: [], tags: [].}
proc copy(p: SexpNode): SexpNode {...}{.raises: [], tags: [].}
proc pretty(node: SexpNode; indent = 2): string {...}{.raises: [], tags: [].}
proc `$`(node: SexpNode): string {...}{.raises: [], tags: [].}
proc open(my: var SexpParser; input: Stream) {...}{.raises: [Exception], tags: [ReadIOEffect].}
proc parseSexp(s: Stream): SexpNode {...}{.raises: [Exception, ValueError, SexpParsingError], tags: [ReadIOEffect].}
proc parseSexp(buffer: string): SexpNode {...}{.raises: [Exception, ValueError, SexpParsingError], tags: [ReadIOEffect].}
iterator items(node: SexpNode): SexpNode {...}{.raises: [], tags: [].}
iterator mitems(node: var SexpNode): var SexpNode {...}{.raises: [], tags: [].}
macro convertSexp(x: untyped): untyped
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/sexp.html