Documentation
¶
Overview ¶
Package bonsaijavascript provides a tree-sitter JavaScript parser built on the bonsai snapshot runtime.
Typical use:
p := bonsaijavascript.NewParser()
root, err := p.Parse(src)
if err != nil { ... }
for n := range root.Find("function_declaration") { ... }
The Parser, Node, and Point types are aliases for the corresponding bonsai runtime types, so values flow naturally between bonsai-aware code and this package.
The wasm module + grammar are generated. See Dockerfile.builder at the repo root. `go generate ./bonsai-javascript` regenerates module_gen.{go,dat}, libc_gen.go, and meta_gen.go in this directory.
Grammar source: https://github.com/tree-sitter/tree-sitter-javascript
Index ¶
- Constants
- Variables
- type Memory
- type Module
- func (m *Module) X__indirect_function_table() *[]any
- func (m *Module) X_initialize()
- func (m *Module) Xfree(v0 int32)
- func (m *Module) Xmalloc(v0 int32) int32
- func (m *Module) Xtree_sitter_javascript() int32
- func (m *Module) Xts_node_end_byte(v0 int32) int32
- func (m *Module) Xts_node_end_point(v0, v1 int32)
- func (m *Module) Xts_node_has_error(v0 int32) int32
- func (m *Module) Xts_node_is_error(v0 int32) int32
- func (m *Module) Xts_node_is_missing(v0 int32) int32
- func (m *Module) Xts_node_is_named(v0 int32) int32
- func (m *Module) Xts_node_is_null(v0 int32) int32
- func (m *Module) Xts_node_start_byte(v0 int32) int32
- func (m *Module) Xts_node_start_point(v0, v1 int32)
- func (m *Module) Xts_node_string(v0 int32) int32
- func (m *Module) Xts_node_type(v0 int32) int32
- func (m *Module) Xts_parser_delete(v0 int32)
- func (m *Module) Xts_parser_new() int32
- func (m *Module) Xts_parser_parse_string(v0, v1, v2, v3 int32) int32
- func (m *Module) Xts_parser_set_language(v0, v1 int32) int32
- func (m *Module) Xts_tree_cursor_current_field_name(v0 int32) int32
- func (m *Module) Xts_tree_cursor_current_node(v0, v1 int32)
- func (m *Module) Xts_tree_cursor_delete(v0 int32)
- func (m *Module) Xts_tree_cursor_goto_first_child(v0 int32) int32
- func (m *Module) Xts_tree_cursor_goto_next_sibling(v0 int32) int32
- func (m *Module) Xts_tree_cursor_goto_parent(v0 int32) int32
- func (m *Module) Xts_tree_cursor_new(v0, v1 int32)
- func (m *Module) Xts_tree_delete(v0 int32)
- func (m *Module) Xts_tree_root_node(v0, v1 int32)
- type Node
- type Parser
- type Point
- type Xenv
Constants ¶
const ( KindArguments = "arguments" KindArray = "array" KindArrayPattern = "array_pattern" KindArrowFunction = "arrow_function" KindAssignmentExpression = "assignment_expression" KindAssignmentPattern = "assignment_pattern" KindAugmentedAssignmentExpression = "augmented_assignment_expression" KindAwaitExpression = "await_expression" KindBinaryExpression = "binary_expression" KindBreakStatement = "break_statement" KindCallExpression = "call_expression" KindCatchClause = "catch_clause" KindClass = "class" KindClassBody = "class_body" KindClassDeclaration = "class_declaration" KindClassHeritage = "class_heritage" KindClassStaticBlock = "class_static_block" KindComment = "comment" KindComputedPropertyName = "computed_property_name" KindContinueStatement = "continue_statement" KindDebuggerStatement = "debugger_statement" KindDecorator = "decorator" KindDoStatement = "do_statement" KindElseClause = "else_clause" KindEmptyStatement = "empty_statement" KindEscapeSequence = "escape_sequence" KindExportClause = "export_clause" KindExportSpecifier = "export_specifier" KindExportStatement = "export_statement" KindExpressionStatement = "expression_statement" KindFalse = "false" KindFieldDefinition = "field_definition" KindFinallyClause = "finally_clause" KindForInStatement = "for_in_statement" KindForStatement = "for_statement" KindFormalParameters = "formal_parameters" KindFunctionDeclaration = "function_declaration" KindFunctionExpression = "function_expression" KindGeneratorFunction = "generator_function" KindGeneratorFunctionDeclaration = "generator_function_declaration" KindHashBangLine = "hash_bang_line" KindHtmlCharacterReference = "html_character_reference" KindHtmlComment = "html_comment" KindIdentifier = "identifier" KindIfStatement = "if_statement" KindImport = "import" KindImportAttribute = "import_attribute" KindImportClause = "import_clause" KindImportSpecifier = "import_specifier" KindImportStatement = "import_statement" KindJsxAttribute = "jsx_attribute" KindJsxClosingElement = "jsx_closing_element" KindJsxElement = "jsx_element" KindJsxExpression = "jsx_expression" KindJsxNamespaceName = "jsx_namespace_name" KindJsxOpeningElement = "jsx_opening_element" KindJsxSelfClosingElement = "jsx_self_closing_element" KindJsxText = "jsx_text" KindLabeledStatement = "labeled_statement" KindLexicalDeclaration = "lexical_declaration" KindMemberExpression = "member_expression" KindMetaProperty = "meta_property" KindMethodDefinition = "method_definition" KindNamedImports = "named_imports" KindNamespaceExport = "namespace_export" KindNamespaceImport = "namespace_import" KindNewExpression = "new_expression" KindNull = "null" KindNumber = "number" KindObject = "object" KindObjectAssignmentPattern = "object_assignment_pattern" KindObjectPattern = "object_pattern" KindOptionalChain = "optional_chain" KindPair = "pair" KindPairPattern = "pair_pattern" KindParenthesizedExpression = "parenthesized_expression" KindPrivatePropertyIdentifier = "private_property_identifier" KindProgram = "program" KindPropertyIdentifier = "property_identifier" KindRegex = "regex" KindRegexFlags = "regex_flags" KindRegexPattern = "regex_pattern" KindRestPattern = "rest_pattern" KindReturnStatement = "return_statement" KindSequenceExpression = "sequence_expression" KindShorthandPropertyIdentifier = "shorthand_property_identifier" KindShorthandPropertyIdentifierPattern = "shorthand_property_identifier_pattern" KindSpreadElement = "spread_element" KindStatementBlock = "statement_block" KindStatementIdentifier = "statement_identifier" KindString = "string" KindStringFragment = "string_fragment" KindSubscriptExpression = "subscript_expression" KindSuper = "super" KindSwitchBody = "switch_body" KindSwitchCase = "switch_case" KindSwitchDefault = "switch_default" KindSwitchStatement = "switch_statement" KindTemplateString = "template_string" KindTemplateSubstitution = "template_substitution" KindTernaryExpression = "ternary_expression" KindThis = "this" KindThrowStatement = "throw_statement" KindTrue = "true" KindTryStatement = "try_statement" KindUnaryExpression = "unary_expression" KindUndefined = "undefined" KindUpdateExpression = "update_expression" KindUsingDeclaration = "using_declaration" KindVariableDeclaration = "variable_declaration" KindVariableDeclarator = "variable_declarator" KindWhileStatement = "while_statement" KindWithStatement = "with_statement" KindYieldExpression = "yield_expression" )
KindX constants name every named, visible node type this grammar can produce as Node.Kind. Values are the raw tree-sitter kind strings, so they work anywhere a node kind string is expected, like Node.Find. Anonymous tokens (keywords, punctuation) and supertypes have no constants.
const ( FieldAlias = "alias" FieldAlternative = "alternative" FieldArgument = "argument" FieldArguments = "arguments" FieldAttribute = "attribute" FieldBody = "body" FieldCloseTag = "close_tag" FieldCondition = "condition" FieldConsequence = "consequence" FieldConstructor = "constructor" FieldDeclaration = "declaration" FieldDecorator = "decorator" FieldFinalizer = "finalizer" FieldFlags = "flags" FieldFunction = "function" FieldHandler = "handler" FieldIncrement = "increment" FieldIndex = "index" FieldInitializer = "initializer" FieldKey = "key" FieldKind = "kind" FieldLabel = "label" FieldLeft = "left" FieldMember = "member" FieldName = "name" FieldObject = "object" FieldOpenTag = "open_tag" FieldOperator = "operator" FieldOptionalChain = "optional_chain" FieldParameter = "parameter" FieldParameters = "parameters" FieldPattern = "pattern" FieldProperty = "property" FieldRight = "right" FieldSource = "source" FieldValue = "value" )
FieldX constants name every field this grammar attaches to child nodes, for Node.ChildByField and Node.Field.
const GrammarVersion = "v0.25.0"
GrammarVersion is the upstream grammar ref (tag or branch) this module's parser was generated from. The exact commit is in the header above.
const InitialPages = 7
InitialPages is the wasm module's declared initial linear-memory size, in 64 KiB WebAssembly pages. Memory passed to New must already be sized to at least InitialPages * 65536 bytes before the call.
const TreeSitterVersion = "v0.25.10"
TreeSitterVersion is the tree-sitter runtime ref whose compiled form this module embeds.
Variables ¶
var LicenseGrammar string
LicenseGrammar is the license of the grammar (https://github.com/tree-sitter/tree-sitter-javascript.git @ v0.25.0) whose compiled form this package embeds.
var LicenseTreeSitter string
LicenseTreeSitter is the license of the tree-sitter runtime (v0.25.10) whose compiled form this package embeds.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func (*Module) X__indirect_function_table ¶
func (*Module) X_initialize ¶
func (m *Module) X_initialize()