Skip to content

fir.generic.parser

A parser that works with the format provided by the generic backend.

You can see an example of parser output here.

Helpers

Several functions that aid in the process of parsing.

Element Summary
Functions
determineSummaryBoundary Gets the boundary line where a summary ends and the description begins
parseDescription Parses codeblocks, tags, headers and normal text in descriptions.
Types
DescriptionLine A single element in a description returned by parseDescription

determineSummaryBoundary 

:: content:GenericComment.content, lead:string -> boundary:number

Gets the boundary line where a summary ends and the description begins

  • Gets the boundary line where a summary ends and the description begins

parseDescription 

:: description:[string] -> description:[DescriptionLine], tags:[string]

Parses codeblocks, tags, headers and normal text in descriptions.

Notes

  • In a codeblock, the first character of every line is removed (for a space).

Supported tags

  • @internal - Adds an internal true flag to the element.

DescriptionLine 

A single element in a description returned by parseDescription

DescriptionLine {
  type      :: string (text|snippet|header)
  content   :: [string]
  language? :: string -- only when type is snippet
  title?    :: string -- only when type is snippet
  n?        :: number -- only when type is header
}

API

This is the API provided to work with the generic parser.

Element Summary
Functions
parse Parses a list of GenericComments into a GenericAST
Types
GenericAST The AST produced by parse.

parse 

:: comments:[GenericComment], language:Language -> ast:GenericAST

Parses a list of GenericComments into a GenericAST

  • Parses a list of GenericComments into a GenericAST

GenericAST 

Aliases: GenericSection, GenericSectionContent, GenericElement

The AST produced by parse.

GenericAST {
  title       :: string
  description :: [DescriptionLine]
  [n]         :: GenericSection { -- where n is the ID of the section
    section :: GenericSectionDetails {
      id          :: number
      name        :: string
      description :: [DescriptionLine]
    }
    content :: GenericSectionContent {
      [name] :: GenericElement {
        is          :: string (type|function|constant|class)
        description :: [DescriptionLine]
        name        :: [string] -- an array, meant to also contain aliases
        summary     :: string
        type        :: string -- only when `is` is `"function"` or `"constant"`
      }
    }
  }
}