Skip to content

Instantly share code, notes, and snippets.

@watzon
Last active July 19, 2017 22:20
Show Gist options
  • Save watzon/93b71ff2fc8f336f394be4b8bfa6e984 to your computer and use it in GitHub Desktop.
Save watzon/93b71ff2fc8f336f394be4b8bfa6e984 to your computer and use it in GitHub Desktop.
type
NodeKind = enum
nkValue,
nkLiteral,
nkSymbol,
nkPair,
nkLookupVal,
nkIf,
nkIfAsync,
nkInlineIf,
nkFor,
nkAsyncEach,
nkAsyncAll,
nkMacro,
nkCaller,
nkImport,
nkFromImport,
nkFunCall,
nkFilter,
nkFilterAsync,
nkBlock,
nkSuper,
nkTemplateRef,
nkExtends,
nkInclude,
nkSet,
nkCapture,
nkTemplateData,
nkUnaryOp,
nkBinaryOp,
nkIn,
nkOr,
nkAnd,
nkNot,
nkAdd,
nkConcat,
nkSub,
nkMul,
nkDiv,
nkFloorDiv,
nkMod,
nkPow,
nkNeg,
nkPos,
nkCompare,
nkCompareOperand,
nkCallExtension,
nkCallExtensionAsync
Node* = ref NodeObj
NodeObj = object
nodeId* : int
line*, column* : int
case kind: NodeKind
of nkValue, nkSymbol, nkLiteral, nkTemplateData:
value: string
of nkPair:
pairKey, pairValue: string
of nkLookupVal:
lookupTarget, lookupVal: string
of nkIf, nkInlineIf, nkIfAsync:
ifCond, ifBody, ifElse: string
of nkFor, nkAsyncEach, nkAsyncAll:
forArr: seq[Node]
forName, forBody, forElse: string
of nkMacro, nkCaller:
macroName, macroBody: string
macroArgs: seq[string]
of nkImport:
importTemplate, importTarget: string
importWithContext: bool
of nkFromImport:
fiTemplate: string
fiName: seq[string]
fiWithContext: bool
of nkFunCall, nkFilter:
funName: string
funArgs: seq[string]
of nkFilterAsync:
filterName, filterSymbol: string
filterArgs: seq[string]
of nkBlock:
blkName, blkBody: string
of nkSuper:
sBlockName, sSymbol: string
of nkTemplateRef, nkExtends:
templateName: string
of nkInclude:
incTemplateName: string
incIgnoreMissing: bool
of nkSet:
setTargets: seq[string]
setValue: string
of nkCapture:
captureBody: string
of nkUnaryOp, nkNeg, nkPos:
target: string
of nkBinaryOp, nkIn, nkOr, nkAnd, nkNot, nkAdd, nkConcat, nkSub, nkMul, nkDiv, nkFloorDiv, nkMod, nkPow:
left, right: string
of nkCompare:
expression: string
ops: seq[string]
of nkCompareOperand:
opExpression, opType: string
of nkCallExtension, nkCallExtensionAsync:
extName, extProp: string
extArgs, extContentArgs: seq[string]
NodeListKind = enum
nlkRoot,
nlkGroup,
nlkArray,
nlkDict,
nlkKeywordArgs
NodeList* = ref NodeListObj
NodeListObj = object
listId* : int
line*, column* : int
case kind: NodeListKind
of nlkRoot, nlkGroup, nlkArray, nlkDict, nlkKeywordArgs:
children* : seq[Node]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment