Source   Edit

This module implements an AST for the reStructuredText parser.


FileIndex = distinct int32
  Source   Edit
PRstNode = ref RstNode
an RST node   Source   Edit
RstNode {.acyclic, final.} = object
  case kind*: RstNodeKind    ## the node's kind
  of rnLeaf, rnSmiley:
      text*: string          ## string that is expected to be displayed
  of rnEnumList:
      labelFmt*: string      ## label format like "(1)"
  of rnLineBlockItem:
      lineIndent*: string    ## a few spaces or newline at the line beginning
  of rnAdmonition:
      adType*: string        ## admonition type: "note", "caution", etc. This
                             ## text will set the style and also be displayed
  of rnOverline, rnHeadline, rnMarkdownHeadline:
      level*: int            ## level of headings starting from 1 (main
                             ## chapter) to larger ones (minor sub-sections)
                             ## level=0 means it's document title or subtitle
  of rnFootnote, rnCitation, rnOptionListItem:
      order*: int            ## footnote order (for auto-symbol footnotes and
                             ## auto-numbered ones without a label)
  of rnRef, rnSubstitutionReferences, rnInterpretedText, rnField, rnInlineCode,
     rnCodeBlock, rnFootnoteRef:
      info*: TLineInfo       ## To have line/column info for warnings at
                             ## nodes that are post-processed after parsing

  anchor*: string            ## anchor, internal link target
                             ## (aka HTML id tag, aka Latex label/hypertarget)
  sons*: RstNodeSeq          ## the node's sons
AST node (result of RST parsing)   Source   Edit
RstNodeKind = enum
  rnInner, rnHeadline, rnOverline, rnMarkdownHeadline, rnTransition,
  rnParagraph, rnBulletList, rnBulletItem, rnEnumList, rnEnumItem, rnDefList,
  rnDefItem, rnDefName, rnDefBody, rnFieldList, rnField, rnFieldName,
  rnFieldBody, rnOptionList, rnOptionListItem, rnOptionGroup, rnOption,
  rnOptionString, rnOptionArgument, rnDescription, rnLiteralBlock,
  rnQuotedLiteralBlock, rnLineBlock, rnLineBlockItem, rnBlockQuote, rnTable,
  rnGridTable, rnMarkdownTable, rnTableRow, rnTableHeaderCell, rnTableDataCell,
  rnFootnote, rnCitation, rnFootnoteGroup, rnStandaloneHyperlink, rnHyperlink,
  rnRef, rnInternalRef, rnFootnoteRef, rnDirective, rnDirArg, rnRaw, rnTitle,
  rnContents, rnImage, rnFigure, rnCodeBlock, rnAdmonition, rnRawHtml,
  rnRawLatex, rnContainer, rnIndex, rnSubstitutionDef, rnInlineCode,
  rnCodeFragment, rnUnknownRole, rnSub, rnSup, rnIdx, rnEmphasis,
  rnStrongEmphasis, rnTripleEmphasis, rnInterpretedText, rnInlineLiteral,
  rnInlineTarget, rnSubstitutionReferences, rnSmiley, rnDefaultRole, rnLeaf
the possible node kinds of an PRstNode   Source   Edit
TLineInfo = object
  line*: uint16
  col*: int16
  fileIndex*: FileIndex
  Source   Edit


proc `==`(a, b: FileIndex): bool {.borrow, ...raises: [], tags: [].}
  Source   Edit
proc add(father, son: PRstNode) {....raises: [], tags: [].}
  Source   Edit
proc add(father: PRstNode; s: string) {....raises: [], tags: [].}
  Source   Edit
proc addIfNotNil(father, son: PRstNode) {....raises: [], tags: [].}
  Source   Edit
proc lastSon(n: PRstNode): PRstNode {....raises: [], tags: [].}
  Source   Edit
proc len(n: PRstNode): int {....raises: [], tags: [].}
  Source   Edit
proc newRstLeaf(s: string): PRstNode {....raises: [], tags: [].}
  Source   Edit
proc newRstNode(kind: RstNodeKind; info: TLineInfo; sons: seq[PRstNode] = @[]): PRstNode {.
    ...raises: [], tags: [].}
  Source   Edit
proc newRstNode(kind: RstNodeKind; s: string): PRstNode {....deprecated,
    raises: [], tags: [].}
  Source   Edit
proc newRstNode(kind: RstNodeKind; sons: seq[PRstNode] = @[]; anchor = ""): PRstNode {.
    ...raises: [], tags: [].}
  Source   Edit
proc renderRstToJson(node: PRstNode): string {....raises: [], tags: [].}
Writes the given RST node as JSON that is in the form
  "kind":string node.kind,
  "text":optional string node.text,
  "level":optional int node.level,
  "sons":optional node array
  Source   Edit
proc renderRstToRst(n: PRstNode; result: var string) {....raises: [Exception],
    tags: [RootEffect].}
renders n into its string representation and appends to result.   Source   Edit
proc renderRstToText(node: PRstNode): string {....raises: [], tags: [].}
minimal text representation of markup node   Source   Edit
proc treeRepr(node: PRstNode; indent = 0): string {....raises: [], tags: [].}
Writes the parsed RST node into an AST tree with compact string representation in the format (one line per every sub-node): indent - kind - [text|level|order|adType] - anchor (if non-zero) (suitable for debugging of RST parsing).   Source   Edit