textmate_grammar.parsers.base

Module Contents

Classes

DummyParser

A dummy parser object

LanguageParser

The parser of a language grammar.

Data

API

textmate_grammar.parsers.base.LANGUAGE_PARSERS = None
class textmate_grammar.parsers.base.DummyParser[source]

Bases: textmate_grammar.parser.GrammarParser

A dummy parser object

Initialization

Initialize a Parser object.

Parameters:
  • grammar – The grammar dictionary.

  • language – The language parser object. Defaults to None.

  • key – The key for the parser. Defaults to “”.

  • is_capture – Indicates if the parser is a capture. Defaults to False.

  • kwargs – Additional keyword arguments.

Returns:

None

class textmate_grammar.parsers.base.LanguageParser(grammar: dict, **kwargs)[source]

Bases: textmate_grammar.parser.PatternsParser

The parser of a language grammar.

Initialization

Initialize a Language object.

Parameters:
  • grammar (dict) – The grammar definition for the language.

  • pre_processor (BasePreProcessor) – A pre-processor to use on the input string of the parser

  • kwargs – Additional keyword arguments.

Variables:
  • name – The name of the language.

  • uuid – The UUID of the language.

  • file_types – The file types associated with the language.

  • token – The scope name of the language.

  • repository – The repository of grammar rules for the language.

  • injections – The list of injection rules for the language.

  • _cache – The cache object for the language.

pre_process(input: str) str[source]

Pre-processes the input string before parsing.

This method can be overloaded in language specific parsers with custom pre-processing logic.

parse_file(filePath: str | pathlib.Path, **kwargs) textmate_grammar.elements.ContentElement | None[source]

Parses an entire file with the current grammar.

Parameters:
  • filePath – The path to the file to be parsed.

  • kwargs – Additional keyword arguments to be passed to the parser.

Returns:

The parsed element if successful, None otherwise.

parse_string(input: str, **kwargs) textmate_grammar.elements.ContentElement | None[source]

Parses an input string.

Parameters:
  • input – The input string to be parsed.

  • kwargs – Additional keyword arguments.

Returns:

The result of parsing the input string.