The parsesql
module implements a high performance SQL file parser. It parses PostgreSQL syntax and the SQL ANSI standard.
SqlLexer = object of BaseLexer filename: string
SqlNodeKind = enum nkNone, nkIdent, nkQuotedIdent, nkStringLit, nkBitStringLit, nkHexStringLit, nkIntegerLit, nkNumericLit, nkPrimaryKey, nkForeignKey, nkNotNull, nkNull, nkStmtList, nkDot, nkDotDot, nkPrefix, nkInfix, nkCall, nkPrGroup, nkColumnReference, nkReferences, nkDefault, nkCheck, nkConstraint, nkUnique, nkIdentity, nkColumnDef, ## name, datatype, constraints nkInsert, nkUpdate, nkDelete, nkSelect, nkSelectDistinct, nkSelectColumns, nkSelectPair, nkAsgn, nkFrom, nkFromItemPair, nkGroup, nkLimit, nkHaving, nkOrder, nkJoin, nkDesc, nkUnion, nkIntersect, nkExcept, nkColumnList, nkValueList, nkWhere, nkCreateTable, nkCreateTableIfNotExists, nkCreateType, nkCreateTypeIfNotExists, nkCreateIndex, nkCreateIndexIfNotExists, nkEnumDef
SqlParseError = object of ValueError
SqlNode = ref SqlNodeObj
SqlNodeObj = object case kind*: SqlNodeKind ## kind of syntax tree of LiteralNodes: strVal*: string ## AST leaf: the identifier, numeric literal ## string literal, etc. else: sons*: seq[SqlNode] ## the node's children
SqlParser = object of SqlLexer tok: Token
proc newNode(k: SqlNodeKind): SqlNode {...}{.raises: [], tags: [].}
proc newNode(k: SqlNodeKind; s: string): SqlNode {...}{.raises: [], tags: [].}
proc newNode(k: SqlNodeKind; sons: seq[SqlNode]): SqlNode {...}{.raises: [], tags: [].}
proc len(n: SqlNode): int {...}{.raises: [], tags: [].}
proc `[]`(n: SqlNode; i: int): SqlNode {...}{.raises: [], tags: [].}
proc add(father, n: SqlNode) {...}{.raises: [], tags: [].}
proc renderSQL(n: SqlNode; upperCase = false): string {...}{.raises: [Exception], tags: [RootEffect].}
proc `$`(n: SqlNode): string {...}{.raises: [Exception], tags: [RootEffect].}
proc parseSQL(input: Stream; filename: string): SqlNode {...}{. raises: [Exception, Exception, ValueError, SqlParseError], tags: [ReadIOEffect, RootEffect].}
proc parseSQL(input: string; filename = ""): SqlNode {...}{. raises: [Exception, ValueError, SqlParseError], tags: [ReadIOEffect, RootEffect].}
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/parsesql.html