# Module parsesql

The `parsesql` module implements a high performance SQL file parser. It parses PostgreSQL syntax and the SQL ANSI standard.

# Imports

hashes, strutils, lexbase, streams

# Types

    TSqlLexer = object of TBaseLexer
      filename: string

  the parser object.

    TSqlNodeKind = enum
      nkNone, nkIdent, nkStringLit, nkBitStringLit, nkHexStringLit, nkIntegerLit,
      nkNumericLit, nkPrimaryKey, nkForeignKey, nkNotNull, nkStmtList, nkDot,
      nkDotDot, nkPrefix, nkInfix, nkCall, nkColumnReference, nkReferences,
      nkDefault, nkCheck, nkConstraint, nkUnique, nkIdentity, nkColumnDef, ## name, datatype, constraints
      nkInsert, nkUpdate, nkDelete, nkSelect, nkSelectDistinct, nkSelectColumns,
      nkAsgn, nkFrom, nkGroup, nkHaving, nkOrder, nkDesc, nkUnion, nkIntersect,
      nkExcept, nkColumnList, nkValueList, nkWhere, nkCreateTable,
      nkCreateTableIfNotExists, nkCreateType, nkCreateTypeIfNotExists,
      nkCreateIndex, nkCreateIndexIfNotExists, nkEnumDef

  kind of SQL abstract syntax tree

    EInvalidSql = object of EInvalidValue

  Invalid SQL encountered

    PSqlNode = ref TSqlNode

  an SQL abstract syntax tree node

    TSqlNode = object
      case kind*: TSqlNodeKind    ## kind of syntax tree
      of nkIdent, nkStringLit, nkBitStringLit, nkHexStringLit, nkIntegerLit,
         nkNumericLit:
          strVal*: string         ## AST leaf: the identifier, numeric literal
                                  ## string literal, etc.

      else:
          sons*: seq[PSqlNode]    ## the node's children

  an SQL abstract syntax tree node

    TSqlParser = object of TSqlLexer
      tok: TToken

  SQL parser object

# Procs

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

    proc add(father, n: PSqlNode) {.raises: [], tags: [].}

    proc parseSQL(input: PStream; filename: string): PSqlNode {.
        raises: [E_Base, E_Base, EInvalidValue, EInvalidSql],
        tags: [FReadIO, TEffect].}

  parses the SQL from input into an AST and returns the AST. filename is only used for error messages. Syntax errors raise an EInvalidSql exception.

    proc renderSQL(n: PSqlNode): string {.raises: [E_Base], tags: [TEffect].}

  Converts an SQL abstract syntax tree to its string representation.

Generated: 2013-05-21 09:55:11 UTC