# compiler/parser

Dark Mode

- Index

Search:
Group by:
Source Edit

# Imports

llstream, lexer, idents, ast, msgs, options, lineinfos, pathutils

# Types

    Parser = object
      currInd: int
      firstTok: bool
      hasProgress: bool
      lex*: Lexer
      tok*: Token
      lineStartPrevious*: int
      lineNumberPrevious*: int
      bufposPrevious*: int
      inPragma*: int
      inSemiStmtList*: int
      emptyNode: PNode
      when defined(nimpretty):
          em*: Emitter

  Source Edit

# Procs

    proc closeParser(p: var Parser) {....raises: [], tags: [].}

  Close a parser, freeing up its resources. Source Edit

    proc eat(p: var Parser; tokType: TokType) {.
        ...raises: [Exception, ValueError, KeyError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Move the parser to the next token if the current token is of type `tokType`, otherwise error. Source Edit

    proc expectIdent(p: Parser) {....raises: [Exception, ValueError, KeyError, IOError,
                                           ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc expectIdentOrKeyw(p: Parser) {....raises: [Exception, ValueError, KeyError,
        IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect,
                                            WriteIOEffect, ReadIOEffect,
                                            ReadEnvEffect].}

  Source Edit

    proc getTok(p: var Parser) {....raises: [Exception, ValueError, KeyError, IOError,
                                          ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Get the next token from the parser's lexer, and store it in the parser's `tok` member. Source Edit

    proc indAndComment(p: var Parser; n: PNode; maybeMissEquals = false) {.
        ...raises: [KeyError, Exception, ValueError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc isOperator(tok: Token): bool {....raises: [], tags: [].}

  Source Edit

    proc newFloatNodeP(kind: TNodeKind; floatVal: BiggestFloat; p: Parser): PNode {.
        ...raises: [], tags: [].}

  Source Edit

    proc newIdentNodeP(ident: PIdent; p: Parser): PNode {....raises: [], tags: [].}

  Source Edit

    proc newIntNodeP(kind: TNodeKind; intVal: BiggestInt; p: Parser): PNode {.
        ...raises: [], tags: [].}

  Source Edit

    proc newNodeP(kind: TNodeKind; p: Parser): PNode {....raises: [], tags: [].}

  Source Edit

    proc newStrNodeP(kind: TNodeKind; strVal: string; p: Parser): PNode {.
        ...raises: [], tags: [].}

  Source Edit

    proc openParser(p: var Parser; fileIdx: FileIndex; inputStream: PLLStream;
                    cache: IdentCache; config: ConfigRef) {.
        ...raises: [IOError, Exception, ValueError, KeyError, ERecoverableError], tags: [
        ReadIOEffect, RootEffect, ReadDirEffect, WriteIOEffect, ReadEnvEffect].}

  Open a parser, using the given arguments to set up its internal state. Source Edit

    proc openParser(p: var Parser; filename: AbsoluteFile; inputStream: PLLStream;
                    cache: IdentCache; config: ConfigRef) {.
        ...raises: [IOError, Exception, ValueError, KeyError, ERecoverableError], tags: [
        ReadIOEffect, RootEffect, ReadDirEffect, WriteIOEffect, ReadEnvEffect].}

  Source Edit

    proc optInd(p: var Parser; n: PNode) {....raises: [KeyError, Exception, ValueError,
        IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect,
                                            WriteIOEffect, ReadIOEffect,
                                            ReadEnvEffect].}

  Source Edit

    proc optPar(p: var Parser) {....raises: [Exception, ValueError, KeyError, IOError,
                                          ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc parLineInfo(p: Parser): TLineInfo {....raises: [], tags: [].}

  Retrieve the line information associated with the parser's current state. Source Edit

    proc parMessage(p: Parser; msg: TMsgKind; arg: string = "") {.
        ...raises: [Exception, ValueError, KeyError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Produce and emit the parser message `arg` to output. Source Edit

    proc parseAll(p: var Parser): PNode {....raises: [Exception, ValueError, KeyError,
        IOError, ERecoverableError], tags: [RootEffect, ReadDirEffect,
                                            WriteIOEffect, ReadIOEffect,
                                            ReadEnvEffect].}

  Parses the rest of the input stream held by the parser into a PNode. Source Edit

    proc parseString(s: string; cache: IdentCache; config: ConfigRef;
                     filename: string = ""; line: int = 0;
                     errorHandler: ErrorHandler = nil): PNode {.
        ...raises: [IOError, Exception, ValueError, KeyError, ERecoverableError], tags: [
        ReadIOEffect, RootEffect, ReadDirEffect, WriteIOEffect, ReadEnvEffect].}

  Parses a string into an AST, returning the top node. `filename` and `line`, although optional, provide info so that the compiler can generate correct error messages referring to the original source. Source Edit

    proc parseSymbol(p: var Parser; mode = smNormal): PNode {.
        ...raises: [Exception, ValueError, KeyError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc parseTopLevelStmt(p: var Parser): PNode {.
        ...raises: [Exception, ValueError, KeyError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Implements an iterator which, when called repeatedly, returns the next top-level statement or emptyNode if end of stream. Source Edit

    proc setBaseFlags(n: PNode; base: NumericalBase) {....raises: [], tags: [].}

  Source Edit

    proc skipComment(p: var Parser; node: PNode) {.
        ...raises: [KeyError, Exception, ValueError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit

    proc skipInd(p: var Parser) {....raises: [Exception, ValueError, KeyError, IOError,
                                           ERecoverableError], tags: [RootEffect,
        ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Source Edit