☰

# sexp

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

Note: Import `nimsuggest/sexp` to use this module

# Types

    SexpError = enum
      errNone,                  ## no error
      errInvalidToken,          ## invalid token
      errParensRiExpected,      ## ``)`` expected
      errQuoteExpected,         ## ``"`` expected
      errEofExpected             ## EOF expected

  enumeration that lists all errors that can occur Source Edit

    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

  enumeration of all events that may occur when parsing Source Edit

    SexpNode = ref SexpNodeObj

  SEXP node Source Edit

    SexpNodeKind = enum
      SNil, SInt, SFloat, SString, SSymbol, SList, SCons

  possible SEXP node types Source Edit

    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:
      of SNil:
        nil

  Source Edit

    SexpParser = object of BaseLexer

  the parser object. Source Edit

    SexpParsingError = object of ValueError

  is raised for a SEXP error Source Edit

# Procs

    proc `$`(node: SexpNode): string {....raises: [], tags: [], forbids: [].}

  Converts `node` to its SEXP Representation on one line. Source Edit

    func `==`(a, b: SexpNode): bool {....raises: [Exception], tags: [RootEffect],
                                      forbids: [].}

  Check two nodes for equality Source Edit

    proc `[]`(node: SexpNode; index: int): SexpNode {....raises: [], tags: [],
        forbids: [].}

  Gets the node at `index` in a List. Result is undefined if `index` is out of bounds Source Edit

    proc add(father, child: SexpNode) {....raises: [], tags: [], forbids: [].}

  Adds `child` to a SList node `father`. Source Edit

    proc close(my: var SexpParser) {.inline, ...raises: [IOError, OSError],
                                     tags: [WriteIOEffect], forbids: [].}

  closes the parser `my` and its associated input stream. Source Edit

    proc copy(p: SexpNode): SexpNode {....raises: [], tags: [], forbids: [].}

  Performs a deep copy of `a`. Source Edit

    proc errorMsg(my: SexpParser): string {....raises: [ValueError], tags: [],
                                            forbids: [].}

  returns a helpful error message for the event `sexpError` Source Edit

    proc errorMsgExpected(my: SexpParser; e: string): string {....raises: [ValueError],
        tags: [], forbids: [].}

  returns an error message "`e` expected" in the same format as the other error messages Source Edit

    proc escapeJson(s: string): string {....raises: [], tags: [], forbids: [].}

  Converts a string `s` to its JSON representation. Source Edit

    proc getColumn(my: SexpParser): int {.inline, ...raises: [], tags: [], forbids: [].}

  get the current column the parser has arrived at. Source Edit

    proc getCons(n: SexpNode; defaults: Cons = (newSNil(), newSNil())): Cons {.
        ...raises: [], tags: [], forbids: [].}

  Retrieves the cons value of a `SList SexpNode`.

  Returns `default` if `n` is not a `SList`.

  Source Edit

    proc getElems(n: SexpNode; default: seq[SexpNode] = @[]): seq[SexpNode] {.
        ...raises: [], tags: [], forbids: [].}

  Retrieves the int value of a `SList SexpNode`.

  Returns `default` if `n` is not a `SList`.

  Source Edit

    proc getFloat(my: SexpParser): float {.inline, ...raises: [ValueError], tags: [],
                                           forbids: [].}

  returns the number for the event: `sexpFloat` Source Edit

    proc getFNum(n: SexpNode; default: float = 0.0): float {....raises: [], tags: [],
        forbids: [].}

  Retrieves the float value of a `SFloat SexpNode`.

  Returns `default` if `n` is not a `SFloat`.

  Source Edit

    proc getInt(my: SexpParser): BiggestInt {.inline, ...raises: [ValueError],
        tags: [], forbids: [].}

  returns the number for the event: `sexpInt` Source Edit

    proc getLine(my: SexpParser): int {.inline, ...raises: [], tags: [], forbids: [].}

  get the current line the parser has arrived at. Source Edit

    proc getNum(n: SexpNode; default: BiggestInt = 0): BiggestInt {....raises: [],
        tags: [], forbids: [].}

  Retrieves the int value of a `SInt SexpNode`.

  Returns `default` if `n` is not a `SInt`.

  Source Edit

    proc getStr(n: SexpNode; default: string = ""): string {....raises: [], tags: [],
        forbids: [].}

  Retrieves the string value of a `SString SexpNode`.

  Returns `default` if `n` is not a `SString`.

  Source Edit

    proc getSymbol(n: SexpNode; default: string = ""): string {....raises: [],
        tags: [], forbids: [].}

  Retrieves the int value of a `SList SexpNode`.

  Returns `default` if `n` is not a `SList`.

  Source Edit

    proc hash(n: SexpNode): Hash {....raises: [Exception], tags: [RootEffect],
                                   forbids: [].}

  Compute the hash for a SEXP node Source Edit

    proc kind(my: SexpParser): SexpEventKind {.inline, ...raises: [], tags: [],
        forbids: [].}

  returns the current event type for the SEXP parser Source Edit

    proc len(n: SexpNode): int {....raises: [], tags: [], forbids: [].}

  If `n` is a `SList`, it returns the number of elements. If `n` is a `JObject`, it returns the number of pairs. Else it returns 0. Source Edit

    proc newSCons(car, cdr: SexpNode): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SCons SexpNode` Source Edit

    proc newSFloat(n: float): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SFloat SexpNode`. Source Edit

    proc newSInt(n: BiggestInt): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SInt SexpNode`. Source Edit

    proc newSList(): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SList SexpNode` Source Edit

    proc newSNil(): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SNil SexpNode`. Source Edit

    proc newSString(s: string): SexpNode {....raises: [], tags: [], forbids: [].}

  Creates a new `SString SexpNode`. Source Edit

    proc newSSymbol(s: string): SexpNode {....raises: [], tags: [], forbids: [].}

  Source Edit

    proc open(my: var SexpParser; input: Stream) {....raises: [IOError, OSError],
        tags: [ReadIOEffect], forbids: [].}

  initializes the parser with an input stream. Source Edit

    proc parseSexp(buffer: string): SexpNode {.
        ...raises: [IOError, OSError, ValueError, SexpParsingError],
        tags: [ReadIOEffect, WriteIOEffect], forbids: [].}

  Parses Sexp from `buffer`. Source Edit

    proc parseSexp(s: Stream): SexpNode {....raises: [IOError, OSError, ValueError,
        SexpParsingError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}

  Parses from a buffer `s` into a `SexpNode`. Source Edit

    proc pretty(node: SexpNode; indent = 2): string {....raises: [], tags: [],
        forbids: [].}

  Converts `node` to its Sexp Representation, with indentation and on multiple lines. Source Edit

    proc raiseParseErr(p: SexpParser; msg: string) {.noinline, noreturn,
        ...raises: [SexpParsingError, ValueError], tags: [], forbids: [].}

  raises an `ESexpParsingError` exception. Source Edit

    proc sexp(b: bool): SexpNode {....raises: [], tags: [], forbids: [].}

  Generic constructor for SEXP data. Creates a new `SSymbol SexpNode` with value t or `SNil SexpNode`. Source Edit

    proc sexp(elements: openArray[SexpNode]): SexpNode {....raises: [], tags: [],
        forbids: [].}

  Generic constructor for SEXP data. Creates a new `SList SexpNode` Source Edit

    proc sexp(n: BiggestInt): SexpNode {....raises: [], tags: [], forbids: [].}

  Generic constructor for SEXP data. Creates a new `SInt SexpNode`. Source Edit

    proc sexp(n: float): SexpNode {....raises: [], tags: [], forbids: [].}

  Generic constructor for SEXP data. Creates a new `SFloat SexpNode`. Source Edit

    proc sexp(s: SexpNode): SexpNode {....raises: [], tags: [], forbids: [].}

  Source Edit

    proc sexp(s: string): SexpNode {....raises: [], tags: [], forbids: [].}

  Generic constructor for SEXP data. Creates a new `SString SexpNode`. Source Edit

    proc str(my: SexpParser): string {.inline, ...raises: [], tags: [], forbids: [].}

  returns the character data for the events: `sexpInt`, `sexpFloat`, `sexpString` Source Edit

# Iterators

    iterator items(node: SexpNode): SexpNode {....raises: [], tags: [], forbids: [].}

  Iterator for the items of `node`. `node` has to be a SList. Source Edit

    iterator mitems(node: var SexpNode): var SexpNode {....raises: [], tags: [],
        forbids: [].}

  Iterator for the items of `node`. `node` has to be a SList. Items can be modified. Source Edit

# Macros

    macro convertSexp(x: untyped): untyped

  Convert an expression to a SexpNode directly, without having to specify `%` for every element. Source Edit