Class Parser

Parses a document based on a Language to produce a Tree.

Analogous to TSParser.

Functions

Parser.new () Create a new parser.

Methods

Parser:language () Get the parser's current language.
Parser:set_language (lang) Set the language that the parser should use for parsing.
Parser:included_ranges () Get the parser's included ranges.
Parser:set_included_ranges (ranges) Set the parser's included ranges.
Parser:parse (old_tree, read) Use the parser to parse some source code and create a syntax tree.
Parser:parse_ (old_tree, read) Like Parser.parse, but the reader function returns a second integer value representing the offset at which the requested chunk of text starts within the string.


Functions

Parser.new ()
Create a new parser.

Returns:

    Parser

Methods

Parser:language ()
Get the parser's current language.

Returns:

    Language
Parser:set_language (lang)
Set the language that the parser should use for parsing.

Parameters:

Parser:included_ranges ()
Get the parser's included ranges.

Returns:

    Range.Array
Parser:set_included_ranges (ranges)
Set the parser's included ranges.

Passing nil or an empty table makes the parser include the entire document.

The given ranges must be sorted in ascending order, and be non-overlapping.

Parameters:

Raises:

Ranges are not in ascending order and non-overlapping.
Parser:parse (old_tree, read)
Use the parser to parse some source code and create a syntax tree.

If you are parsing this document for the first time, pass nil for the old_tree parameter.

Otherwise, pass the previous syntax tree for the old_tree parameter. For this to work correctly, you must have already edited the old syntax tree using Tree:edit so that it matches the source code changes.

The reader function takes a byte offset and a Point, and returns a string containing the text inside the document at the position specified.

An optional integer offset can be returned, such that return text:sub(n) is equivalent to return text, n. The latter is faster. The implementation handles negative indices the same way as string:sub.

Return an empty string or nil to signal end of the document. Note that if n > #text, it is counted as an empty string.

Parameters:

  • old_tree Tree edited syntax tree
  • read function(integer,Point):string,integer reader function

Returns:

    Tree
Parser:parse_ (old_tree, read)
Like Parser.parse, but the reader function returns a second integer value representing the offset at which the requested chunk of text starts within the string.

This is provided so you can avoid having to create substrings, improving performance.

Parameters:

  • old_tree Tree edited syntax tree
  • read function(integer,Point):string,integer reader function

Returns:

    Tree
generated by LDoc 1.5.0 Last updated 2024-04-16 14:22:44