packages/docutils/dochelpers (original) (raw)

Source Edit

Integration helpers between docgen.nim and rst.nim.

Function toLangSymbol(linkText) produces a signature docLink of type LangSymbol in rst.nim, while match(generated, docLink) matches it with generated, produced from PNode by docgen.rst.

Procs

proc match(generated: LangSymbol; docLink: LangSymbol): bool {....raises: [], tags: [], forbids: [].}

Returns true if generated can be a target for docLink. If generated is an overload group then only symKind and name are compared for success.Source Edit

func nimIdentBackticksNormalize(s: string): string {....raises: [], tags: [], forbids: [].}

Normalizes the string s as a Nim identifier.

Unlike nimIdentNormalize removes spaces and backticks.

**Warning:**No checking (e.g. that identifiers cannot start from digits or '_', or that number of backticks is even) is performed.

Example:

doAssert nimIdentBackticksNormalize("Foo_bar") == "Foobar" doAssert nimIdentBackticksNormalize("FoO BAr") == "Foobar" doAssert nimIdentBackticksNormalize("Foo BAR") == "Foobar" doAssert nimIdentBackticksNormalize("Foo BAR") == "Foobar"

doAssert nimIdentBackticksNormalize("_x_y") == "_xy"

Source Edit

proc toLangSymbol(linkText: PRstNode): LangSymbol {....raises: [ValueError], tags: [], forbids: [].}

Parses linkText into a more structured form using a state machine.

This proc is designed to allow link syntax with operators even without escaped backticks inside:

proc *_ proc []_

This proc should be kept in sync with the renderTypes proc from compiler/typesrenderer.nim.

Source Edit