bonsaijava

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bonsaijava provides a tree-sitter Java parser built on the bonsai snapshot runtime.

Typical use:

p := bonsaijava.NewParser()
root, err := p.Parse(src)
if err != nil { ... }
for n := range root.Find("method_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-java` regenerates module_gen.{go,dat}, libc_gen.go, and meta_gen.go in this directory.

Grammar source: https://github.com/tree-sitter/tree-sitter-java

Index

Constants

View Source
const (
	KindAnnotatedType                    = "annotated_type"
	KindAnnotation                       = "annotation"
	KindAnnotationArgumentList           = "annotation_argument_list"
	KindAnnotationTypeBody               = "annotation_type_body"
	KindAnnotationTypeDeclaration        = "annotation_type_declaration"
	KindAnnotationTypeElementDeclaration = "annotation_type_element_declaration"
	KindArgumentList                     = "argument_list"
	KindArrayAccess                      = "array_access"
	KindArrayCreationExpression          = "array_creation_expression"
	KindArrayInitializer                 = "array_initializer"
	KindArrayType                        = "array_type"
	KindAssertStatement                  = "assert_statement"
	KindAssignmentExpression             = "assignment_expression"
	KindAsterisk                         = "asterisk"
	KindBinaryExpression                 = "binary_expression"
	KindBinaryIntegerLiteral             = "binary_integer_literal"
	KindBlock                            = "block"
	KindBlockComment                     = "block_comment"
	KindBooleanType                      = "boolean_type"
	KindBreakStatement                   = "break_statement"
	KindCastExpression                   = "cast_expression"
	KindCatchClause                      = "catch_clause"
	KindCatchFormalParameter             = "catch_formal_parameter"
	KindCatchType                        = "catch_type"
	KindCharacterLiteral                 = "character_literal"
	KindClassBody                        = "class_body"
	KindClassDeclaration                 = "class_declaration"
	KindClassLiteral                     = "class_literal"
	KindCompactConstructorDeclaration    = "compact_constructor_declaration"
	KindConstantDeclaration              = "constant_declaration"
	KindConstructorBody                  = "constructor_body"
	KindConstructorDeclaration           = "constructor_declaration"
	KindContinueStatement                = "continue_statement"
	KindDecimalFloatingPointLiteral      = "decimal_floating_point_literal"
	KindDecimalIntegerLiteral            = "decimal_integer_literal"
	KindDimensions                       = "dimensions"
	KindDimensionsExpr                   = "dimensions_expr"
	KindDoStatement                      = "do_statement"
	KindElementValueArrayInitializer     = "element_value_array_initializer"
	KindElementValuePair                 = "element_value_pair"
	KindEnhancedForStatement             = "enhanced_for_statement"
	KindEnumBody                         = "enum_body"
	KindEnumBodyDeclarations             = "enum_body_declarations"
	KindEnumConstant                     = "enum_constant"
	KindEnumDeclaration                  = "enum_declaration"
	KindEscapeSequence                   = "escape_sequence"
	KindExplicitConstructorInvocation    = "explicit_constructor_invocation"
	KindExportsModuleDirective           = "exports_module_directive"
	KindExpressionStatement              = "expression_statement"
	KindExtendsInterfaces                = "extends_interfaces"
	KindFalse                            = "false"
	KindFieldAccess                      = "field_access"
	KindFieldDeclaration                 = "field_declaration"
	KindFinallyClause                    = "finally_clause"
	KindFloatingPointType                = "floating_point_type"
	KindForStatement                     = "for_statement"
	KindFormalParameter                  = "formal_parameter"
	KindFormalParameters                 = "formal_parameters"
	KindGenericType                      = "generic_type"
	KindGuard                            = "guard"
	KindHexFloatingPointLiteral          = "hex_floating_point_literal"
	KindHexIntegerLiteral                = "hex_integer_literal"
	KindIdentifier                       = "identifier"
	KindIfStatement                      = "if_statement"
	KindImportDeclaration                = "import_declaration"
	KindInferredParameters               = "inferred_parameters"
	KindInstanceofExpression             = "instanceof_expression"
	KindIntegralType                     = "integral_type"
	KindInterfaceBody                    = "interface_body"
	KindInterfaceDeclaration             = "interface_declaration"
	KindLabeledStatement                 = "labeled_statement"
	KindLambdaExpression                 = "lambda_expression"
	KindLineComment                      = "line_comment"
	KindLocalVariableDeclaration         = "local_variable_declaration"
	KindMarkerAnnotation                 = "marker_annotation"
	KindMethodDeclaration                = "method_declaration"
	KindMethodInvocation                 = "method_invocation"
	KindMethodReference                  = "method_reference"
	KindModifiers                        = "modifiers"
	KindModuleBody                       = "module_body"
	KindModuleDeclaration                = "module_declaration"
	KindMultilineStringFragment          = "multiline_string_fragment"
	KindNullLiteral                      = "null_literal"
	KindObjectCreationExpression         = "object_creation_expression"
	KindOctalIntegerLiteral              = "octal_integer_literal"
	KindOpensModuleDirective             = "opens_module_directive"
	KindPackageDeclaration               = "package_declaration"
	KindParenthesizedExpression          = "parenthesized_expression"
	KindPattern                          = "pattern"
	KindPermits                          = "permits"
	KindProgram                          = "program"
	KindProvidesModuleDirective          = "provides_module_directive"
	KindReceiverParameter                = "receiver_parameter"
	KindRecordDeclaration                = "record_declaration"
	KindRecordPattern                    = "record_pattern"
	KindRecordPatternBody                = "record_pattern_body"
	KindRecordPatternComponent           = "record_pattern_component"
	KindRequiresModifier                 = "requires_modifier"
	KindRequiresModuleDirective          = "requires_module_directive"
	KindResource                         = "resource"
	KindResourceSpecification            = "resource_specification"
	KindReturnStatement                  = "return_statement"
	KindScopedIdentifier                 = "scoped_identifier"
	KindScopedTypeIdentifier             = "scoped_type_identifier"
	KindSpreadParameter                  = "spread_parameter"
	KindStaticInitializer                = "static_initializer"
	KindStringFragment                   = "string_fragment"
	KindStringInterpolation              = "string_interpolation"
	KindStringLiteral                    = "string_literal"
	KindSuper                            = "super"
	KindSuperInterfaces                  = "super_interfaces"
	KindSuperclass                       = "superclass"
	KindSwitchBlock                      = "switch_block"
	KindSwitchBlockStatementGroup        = "switch_block_statement_group"
	KindSwitchExpression                 = "switch_expression"
	KindSwitchLabel                      = "switch_label"
	KindSwitchRule                       = "switch_rule"
	KindSynchronizedStatement            = "synchronized_statement"
	KindTemplateExpression               = "template_expression"
	KindTernaryExpression                = "ternary_expression"
	KindThis                             = "this"
	KindThrowStatement                   = "throw_statement"
	KindThrows                           = "throws"
	KindTrue                             = "true"
	KindTryStatement                     = "try_statement"
	KindTryWithResourcesStatement        = "try_with_resources_statement"
	KindTypeArguments                    = "type_arguments"
	KindTypeBound                        = "type_bound"
	KindTypeIdentifier                   = "type_identifier"
	KindTypeList                         = "type_list"
	KindTypeParameter                    = "type_parameter"
	KindTypeParameters                   = "type_parameters"
	KindTypePattern                      = "type_pattern"
	KindUnaryExpression                  = "unary_expression"
	KindUnderscorePattern                = "underscore_pattern"
	KindUpdateExpression                 = "update_expression"
	KindUsesModuleDirective              = "uses_module_directive"
	KindVariableDeclarator               = "variable_declarator"
	KindVoidType                         = "void_type"
	KindWhileStatement                   = "while_statement"
	KindWildcard                         = "wildcard"
	KindYieldStatement                   = "yield_statement"
)

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.

View Source
const (
	FieldAlternative       = "alternative"
	FieldArguments         = "arguments"
	FieldArray             = "array"
	FieldBody              = "body"
	FieldCondition         = "condition"
	FieldConsequence       = "consequence"
	FieldConstructor       = "constructor"
	FieldDeclarator        = "declarator"
	FieldDimensions        = "dimensions"
	FieldElement           = "element"
	FieldField             = "field"
	FieldIndex             = "index"
	FieldInit              = "init"
	FieldInterfaces        = "interfaces"
	FieldKey               = "key"
	FieldLeft              = "left"
	FieldModifiers         = "modifiers"
	FieldModule            = "module"
	FieldModules           = "modules"
	FieldName              = "name"
	FieldObject            = "object"
	FieldOperand           = "operand"
	FieldOperator          = "operator"
	FieldPackage           = "package"
	FieldParameters        = "parameters"
	FieldPattern           = "pattern"
	FieldPermits           = "permits"
	FieldProvided          = "provided"
	FieldProvider          = "provider"
	FieldResources         = "resources"
	FieldRight             = "right"
	FieldScope             = "scope"
	FieldSuperclass        = "superclass"
	FieldTemplateArgument  = "template_argument"
	FieldTemplateProcessor = "template_processor"
	FieldType              = "type"
	FieldTypeArguments     = "type_arguments"
	FieldTypeParameters    = "type_parameters"
	FieldUpdate            = "update"
	FieldValue             = "value"
)

FieldX constants name every field this grammar attaches to child nodes, for Node.ChildByField and Node.Field.

View Source
const GrammarVersion = "v0.23.5"

GrammarVersion is the upstream grammar ref (tag or branch) this module's parser was generated from. The exact commit is in the header above.

View Source
const InitialPages = 8

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.

View Source
const TreeSitterVersion = "v0.25.10"

TreeSitterVersion is the tree-sitter runtime ref whose compiled form this module embeds.

Variables

View Source
var LicenseGrammar string

LicenseGrammar is the license of the grammar (https://github.com/tree-sitter/tree-sitter-java.git @ v0.23.5) whose compiled form this package embeds.

View Source
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 Memory

type Memory = interface {
	Slice() *[]byte
	Grow(delta, max int64) int64
}

type Module

type Module struct {
	// contains filtered or unexported fields
}

func New

func New(v0 Xenv) *Module

func (*Module) X__indirect_function_table

func (m *Module) X__indirect_function_table() *[]any

func (*Module) X_initialize

func (m *Module) X_initialize()

func (*Module) Xfree

func (m *Module) Xfree(v0 int32)

func (*Module) Xmalloc

func (m *Module) Xmalloc(v0 int32) int32

func (*Module) Xtree_sitter_java

func (m *Module) Xtree_sitter_java() int32

func (*Module) Xts_node_end_byte

func (m *Module) Xts_node_end_byte(v0 int32) int32

func (*Module) Xts_node_end_point

func (m *Module) Xts_node_end_point(v0, v1 int32)

func (*Module) Xts_node_has_error

func (m *Module) Xts_node_has_error(v0 int32) int32

func (*Module) Xts_node_is_error

func (m *Module) Xts_node_is_error(v0 int32) int32

func (*Module) Xts_node_is_missing

func (m *Module) Xts_node_is_missing(v0 int32) int32

func (*Module) Xts_node_is_named

func (m *Module) Xts_node_is_named(v0 int32) int32

func (*Module) Xts_node_is_null

func (m *Module) Xts_node_is_null(v0 int32) int32

func (*Module) Xts_node_start_byte

func (m *Module) Xts_node_start_byte(v0 int32) int32

func (*Module) Xts_node_start_point

func (m *Module) Xts_node_start_point(v0, v1 int32)

func (*Module) Xts_node_string

func (m *Module) Xts_node_string(v0 int32) int32

func (*Module) Xts_node_type

func (m *Module) Xts_node_type(v0 int32) int32

func (*Module) Xts_parser_delete

func (m *Module) Xts_parser_delete(v0 int32)

func (*Module) Xts_parser_new

func (m *Module) Xts_parser_new() int32

func (*Module) Xts_parser_parse_string

func (m *Module) Xts_parser_parse_string(v0, v1, v2, v3 int32) int32

func (*Module) Xts_parser_set_language

func (m *Module) Xts_parser_set_language(v0, v1 int32) int32

func (*Module) Xts_tree_cursor_current_field_name

func (m *Module) Xts_tree_cursor_current_field_name(v0 int32) int32

func (*Module) Xts_tree_cursor_current_node

func (m *Module) Xts_tree_cursor_current_node(v0, v1 int32)

func (*Module) Xts_tree_cursor_delete

func (m *Module) Xts_tree_cursor_delete(v0 int32)

func (*Module) Xts_tree_cursor_goto_first_child

func (m *Module) Xts_tree_cursor_goto_first_child(v0 int32) int32

func (*Module) Xts_tree_cursor_goto_next_sibling

func (m *Module) Xts_tree_cursor_goto_next_sibling(v0 int32) int32

func (*Module) Xts_tree_cursor_goto_parent

func (m *Module) Xts_tree_cursor_goto_parent(v0 int32) int32

func (*Module) Xts_tree_cursor_new

func (m *Module) Xts_tree_cursor_new(v0, v1 int32)

func (*Module) Xts_tree_delete

func (m *Module) Xts_tree_delete(v0 int32)

func (*Module) Xts_tree_root_node

func (m *Module) Xts_tree_root_node(v0, v1 int32)

type Node

type Node = bonsai.Node

Type aliases so callers can import only this package.

type Parser

type Parser = bonsai.Parser

Type aliases so callers can import only this package.

func NewParser

func NewParser() *Parser

NewParser instantiates a tree-sitter Java parser.

The parser owns one wasm module instance and is NOT safe for concurrent use. Pool a Parser per goroutine. Reuse across files. Instantiation is the expensive part.

type Point

type Point = bonsai.Point

Type aliases so callers can import only this package.

type Xenv

type Xenv = interface {
	Xfputc(v0, v1 int32) int32
	Xmemory() Memory
	Xts_language_is_wasm(v0 int32) int32
	Xts_wasm_store_delete(v0 int32)
	Xvfprintf(v0, v1, v2 int32) int32
	Xvsnprintf(v0, v1, v2, v3 int32) int32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL