Skip to content

APIs

grammar

view_grammar

view_grammar(config: GrammarConfig) -> None
['name',
'inherits',
'rules',
'extras',
'precedences',
'externals',
'inline',
'conflicts',
'word',
'supertypes']

amend_dcg_models

parser module-attribute

parser = ArgumentParser(description='Amend Pydantic models.')

args module-attribute

args = parse_args()

replace_patterns_in_file

replace_patterns_in_file(file_path)

models

Rule module-attribute

Rule = Union[AliasRule, BlankRule, StringRule, PatternRule, SymbolRule, SeqRule, ChoiceRule, Repeat1Rule, RepeatRule, TokenRule, FieldRule, PrecRule]

BlankRule

Bases: BaseModel

type instance-attribute
type: Literal['BLANK']

StringRule

Bases: BaseModel

type instance-attribute
type: Literal['STRING']
value instance-attribute
value: str

PatternRule

Bases: BaseModel

type instance-attribute
type: Literal['PATTERN']
value instance-attribute
value: str
flags class-attribute instance-attribute
flags: str | None = None

SymbolRule

Bases: BaseModel

type instance-attribute
type: Literal['SYMBOL']
name instance-attribute
name: str

TreeSitterGrammarSpecification

Bases: BaseModel

model_config class-attribute instance-attribute
model_config = ConfigDict(extra='forbid')
name class-attribute instance-attribute
name: constr(pattern='^[a-zA-Z_]\\w*') = Field(..., description='the name of the grammar')
inherits class-attribute instance-attribute
inherits: constr(pattern='^[a-zA-Z_]\\w*') | None = Field(None, description='the name of the parent grammar')
rules instance-attribute
rules: dict[constr(pattern='^[a-zA-Z_]\\w*$'), Rule]
extras class-attribute instance-attribute
extras: list[Rule] | None = None
precedences class-attribute instance-attribute
precedences: list[list[Rule]] | None = None
externals class-attribute instance-attribute
externals: list[Rule] | None = None
inline class-attribute instance-attribute
inline: list[constr(pattern='^[a-zA-Z_]\\w*$')] | None = None
conflicts class-attribute instance-attribute
conflicts: list[list[constr(pattern='^[a-zA-Z_]\\w*$')]] | None = None
word class-attribute instance-attribute
word: constr(pattern='^[a-zA-Z_]\\w*') | None = None
supertypes class-attribute instance-attribute
supertypes: list[str] | None = Field(None, description='A list of hidden rule names that should be considered supertypes in the generated node types file. See https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types.')

SeqRule

Bases: BaseModel

type instance-attribute
type: Literal['SEQ']
members instance-attribute
members: list[Rule]

ChoiceRule

Bases: BaseModel

type instance-attribute
type: Literal['CHOICE']
members instance-attribute
members: list[Rule]

AliasRule

Bases: BaseModel

type instance-attribute
type: Literal['ALIAS']
value instance-attribute
value: str
named instance-attribute
named: bool
content instance-attribute
content: Rule

RepeatRule

Bases: BaseModel

type instance-attribute
type: Literal['REPEAT']
content instance-attribute
content: Rule

Repeat1Rule

Bases: BaseModel

type instance-attribute
type: Literal['REPEAT1']
content instance-attribute
content: Rule

TokenRule

Bases: BaseModel

type instance-attribute
type: Literal['TOKEN', 'IMMEDIATE_TOKEN']
content instance-attribute
content: Rule

FieldRule

Bases: BaseModel

name instance-attribute
name: str
type instance-attribute
type: Literal['FIELD']
content instance-attribute
content: Rule

PrecRule

Bases: BaseModel

type instance-attribute
type: Literal['PREC', 'PREC_LEFT', 'PREC_RIGHT', 'PREC_DYNAMIC']
value instance-attribute
value: Any
content instance-attribute
content: Rule

view

pprint_model

pprint_model(model) -> str

view_grammar

view_grammar(config: GrammarConfig) -> None
['name',
'inherits',
'rules',
'extras',
'precedences',
'externals',
'inline',
'conflicts',
'word',
'supertypes']

interface

run

run()

cli

handle_validation_error

handle_validation_error(ve: ValidationError) -> None

run

run()

models

GrammarConfig

Bases: BaseModel

input_file class-attribute instance-attribute
input_file: FilePath = default_grammar_file

NodeTypesConfig

Bases: BaseModel

input_file class-attribute instance-attribute
input_file: FilePath = default_node_types_file

nodes

view_node_types

view_node_types(config: NodeTypesConfig) -> None

models

NodeTypeVariant module-attribute

NodeTypeVariant = Union[NodeTypeNamed, NodeTypeWithSubtypes, NodeTypeWithFields, NodeTypeWithFieldsAndChildren]

NodeType

Bases: BaseModel

named instance-attribute
named: bool
type instance-attribute
type: str

NodeSchema

Bases: BaseModel

multiple instance-attribute
multiple: bool
required instance-attribute
required: bool
types instance-attribute
types: list[NodeType]

NodeTypeNamed

Bases: BaseModel

type instance-attribute
type: str
named instance-attribute
named: bool

NodeTypeWithSubtypes

Bases: NodeTypeNamed

subtypes instance-attribute
subtypes: list[NodeType]

NodeTypeWithFields

Bases: NodeTypeNamed

fields instance-attribute
fields: dict[str, NodeSchema]

NodeTypeWithFieldsAndChildren

Bases: NodeTypeWithFields

children instance-attribute
children: NodeSchema

NodeTypesJson

Bases: RootModel

root class-attribute instance-attribute
root: list[NodeTypeVariant] = Field(..., alias='node-types')

view

pprint_model

pprint_model(model) -> str

view_node_types

view_node_types(config: NodeTypesConfig) -> None

paths

package_dir module-attribute

package_dir = parent

py_dir module-attribute

py_dir = package_dir / 'data' / 'languages' / 'python'

default_grammar_file module-attribute

default_grammar_file = py_dir / 'grammar.json'

default_node_types_file module-attribute

default_node_types_file = py_dir / 'node-types.json'