Data structure for the parser results
Types
ParseDiag = object instLoc*: InstantiationInfo location*: TLineInfo case kind*: ParseDiagKind of pdkInvalidIndentationWithForgotEqualSignHint: eqLineInfo*: TLineInfo of pdkUnexpectedToken: expected*: TokType actual*: Token of pdkMissingToken: missedToks*: seq[TokType] of pdkIdentExpected, pdkExprExpected, pdkAsmStmtExpectsStrLit, pdkInconsistentSpacing: found*: Token of pdkWithoutExtraData: nil
- Source Edit
ParseDiagKind = enum pdkInvalidIndentation, pdkInvalidIndentationWithForgotEqualSignHint, pdkNestableRequiresIndentation, pdkIdentExpected, pdkIdentExpectedEmptyAccQuote, pdkExprExpected, pdkMissingToken, pdkUnexpectedToken, pdkAsmStmtExpectsStrLit, pdkFuncNotAllowed, pdkTupleTypeWithPar, pdkMisplacedParameterVar, pdkConceptNotInType, pdkMisplacedExport, pdkPragmaBeforeGenericParameters, pdkInconsistentSpacing, pdkPragmaDoesNotFollowTypeName, pdkEnablePreviewDotOps
- Source Edit
ParsedKindBracket = range[pnkPar .. pnkCurly]
- Source Edit
ParsedKindLiteral = range[pnkCharLit .. pnkCustomLit]
- Source Edit
ParsedKindWithSons = range[pnkCall .. pnkUsingStmt]
- Source Edit
ParsedNode = ref ParsedNodeData
- Source Edit
ParsedNodeData {.final, acyclic.} = object comment*: string fileIndex*: FileIndex case kind*: ParsedNodeKind of pnkError: diag*: ParseDiag of pnkEmpty: line*: uint16 col*: int16 of pnkIdent: startToken*: ParsedToken of pnkCharLit .. pnkUInt64Lit, pnkFloatLit .. pnkFloat64Lit, pnkStrLit .. pnkTripleStrLit, pnkNilLit, pnkCustomLit: lit*: ParsedToken of pnkAccQuoted: quote*: ParsedToken idents*: seq[tuple[ident: PIdent, line: uint16, col: int16]] of pnkCall .. pnkUsingStmt: token*: ParsedToken sons*: seq[ParsedNode]
- The AST is a tree, the nodes can never form a cycle. Source Edit
ParsedNodeKind = enum pnkError, ## currently we don't produce error nodes pnkEmpty, pnkIdent, pnkCharLit, pnkIntLit, pnkInt8Lit, pnkInt16Lit, pnkInt32Lit, pnkInt64Lit, pnkUIntLit, pnkUInt8Lit, pnkUInt16Lit, pnkUInt32Lit, pnkUInt64Lit, pnkFloatLit, pnkFloat32Lit, pnkFloat64Lit, pnkStrLit, pnkRStrLit, pnkTripleStrLit, pnkNilLit, pnkCustomLit, pnkAccQuoted, pnkCall, pnkCommand, pnkCallStrLit, pnkInfix, pnkPrefix, pnkPostfix, pnkExprEqExpr, pnkExprColonExpr, pnkPar, pnkSqrBracket, pnkCurly, pnkTupleConstr, pnkObjConstr, pnkTableConstr, pnkSqrBracketExpr, pnkCurlyExpr, pnkPragmaExpr, pnkPragma, pnkPragmaBlock, pnkDotExpr, pnkIfExpr, pnkIfStmt, pnkElifBranch, pnkElifExpr, pnkElse, pnkElseExpr, pnkCaseStmt, pnkOfBranch, pnkWhenExpr, pnkWhenStmt, pnkForStmt, pnkWhileStmt, pnkBlockExpr, pnkBlockStmt, pnkDiscardStmt, pnkContinueStmt, pnkBreakStmt, pnkReturnStmt, pnkRaiseStmt, pnkYieldStmt, pnkTryStmt, pnkExceptBranch, pnkFinally, pnkDefer, pnkLambda, pnkDo, pnkBind, pnkBindStmt, pnkMixinStmt, pnkCast, pnkStaticStmt, pnkAsgn, pnkGenericParams, pnkFormalParams, pnkStmtList, pnkStmtListExpr, pnkImportStmt, pnkImportExceptStmt, pnkFromStmt, pnkIncludeStmt, pnkExportStmt, pnkExportExceptStmt, pnkTypeSection, pnkConstSection, pnkLetSection, pnkVarSection, pnkProcDef, pnkFuncDef, pnkMethodDef, pnkConverterDef, pnkIteratorDef, pnkMacroDef, pnkTemplateDef, pnkIdentDefs, pnkConstDef, pnkTypeDef, pnkVarTuple, pnkEnumTy, pnkEnumFieldDef, pnkObjectTy, pnkTupleTy, pnkProcTy, pnkIteratorTy, pnkRecList, pnkRecCase, pnkRecWhen, pnkTypeOfExpr, pnkRefTy, pnkVarTy, pnkPtrTy, pnkStaticTy, pnkDistinctTy, pnkMutableTy, pnkTupleClassTy, pnkTypeClassTy, pnkOfInherit, pnkArgList, pnkWith, pnkWithout, pnkAsmStmt, pnkCommentStmt, pnkUsingStmt
- Source Edit
ParsedToken = object line*: uint16 col*: int16 tokType*: TokType ident*: PIdent iNumber*: BiggestInt fNumber*: BiggestFloat base*: NumericalBase literal*: string
- Used instead of Token to save memory Source Edit
Consts
pdkWithExtraData = {pdkInvalidIndentationWithForgotEqualSignHint, pdkUnexpectedToken, pdkMissingToken, pdkIdentExpected, pdkExprExpected, pdkAsmStmtExpectsStrLit, pdkInconsistentSpacing}
- Source Edit
pdkWithoutExtraData = {pdkInvalidIndentation, pdkNestableRequiresIndentation, pdkIdentExpectedEmptyAccQuote, pdkFuncNotAllowed..pdkPragmaBeforeGenericParameters, pdkPragmaDoesNotFollowTypeName..pdkEnablePreviewDotOps}
- Source Edit
pnkCallKinds = {pnkCall, pnkInfix, pnkPrefix, pnkPostfix, pnkCommand, pnkCallStrLit}
- Source Edit
pnkDeclarativeDefs = {pnkProcDef, pnkFuncDef, pnkMethodDef, pnkIteratorDef, pnkConverterDef}
- Source Edit
pnkFloatKinds = {pnkFloatLit..pnkFloat64Lit}
- Source Edit
pnkIntKinds = {pnkCharLit..pnkUInt64Lit}
- Source Edit
pnkParsedKindsWithSons = {pnkCall..pnkUsingStmt}
- Source Edit
pnkRoutineDefs = {pnkProcDef..pnkTemplateDef}
- Source Edit
pnkStrKinds = {pnkStrLit..pnkTripleStrLit}
- Source Edit
Procs
proc `[]=`(node: ParsedNode; idx: int | BackwardsIndex; other: ParsedNode)
- Source Edit
proc `[]`(node: ParsedNode; idx: int | BackwardsIndex): ParsedNode
- Source Edit
proc add(node: ParsedNode; other: ParsedNode) {....raises: [], tags: [].}
- append other to node's sons Source Edit
proc getToken(n: ParsedNode): ParsedToken {....raises: [], tags: [].}
- Source Edit
func info(p: ParsedNode): TLineInfo {.inline, ...raises: [], tags: [].}
- Source Edit
func len(node: ParsedNode): int {....raises: [], tags: [].}
- Number of sons of the parsed node Source Edit
func newEmptyParsedNode(fileIndex: FileIndex; line = unknownLineInfo.line; col = unknownLineInfo.col): ParsedNode {....raises: [], tags: [].}
- Create an empty ParsedNode Source Edit
func newParsedLitNode(kind: ParsedKindLiteral; fileIndex: FileIndex; token: ParsedToken): ParsedNode {....raises: [], tags: [].}
- Create a new leaf literal parsed node. Source Edit
func newParsedNode(kind: ParsedKindWithSons; fileIndex: FileIndex; token: ParsedToken; sons: seq[ParsedNode] = @[]): ParsedNode {. ...raises: [], tags: [].}
- Create a new non-leaf parsed node with a specified location information and sons. Source Edit
func newParsedNodeIdent(fileIndex: FileIndex; token: ParsedToken): ParsedNode {. ...raises: [], tags: [].}
- Create a pnkIdent node Source Edit
proc newProcNode(kind: ParsedNodeKind; fileIndex: FileIndex; token: ParsedToken; body, params, name, pattern, genericParams, pragmas, exceptions: ParsedNode): ParsedNode {. ...raises: [], tags: [].}
- Source Edit
func safeLen(node: ParsedNode): int {....raises: [], tags: [].}
- Source Edit
proc toParsedToken(t: Token): ParsedToken {.inline, ...raises: [], tags: [].}
- Source Edit
proc transitionSonsKind(n: ParsedNode; kind: ParsedNodeKind) {....raises: [], tags: [].}
- Source Edit
Iterators
iterator items(node: ParsedNode): ParsedNode {....raises: [], tags: [].}
- Source Edit
iterator pairs(node: ParsedNode): (int, ParsedNode) {....raises: [], tags: [].}
- Source Edit