Documentation
¶
Overview ¶
Package bonsairuby provides a tree-sitter Ruby parser built on the bonsai snapshot runtime.
Typical use:
p := bonsairuby.NewParser()
root, err := p.Parse(src)
if err != nil { ... }
for n := range root.Find("method") { ... }
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-ruby` regenerates module_gen.{go,dat}, libc_gen.go, and meta_gen.go in this directory.
Grammar source: https://github.com/tree-sitter/tree-sitter-ruby
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_ruby() 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 ( KindAlias = "alias" KindAlternativePattern = "alternative_pattern" KindArgumentList = "argument_list" KindArray = "array" KindArrayPattern = "array_pattern" KindAsPattern = "as_pattern" KindAssignment = "assignment" KindBareString = "bare_string" KindBareSymbol = "bare_symbol" KindBegin = "begin" KindBeginBlock = "begin_block" KindBinary = "binary" KindBlock = "block" KindBlockArgument = "block_argument" KindBlockBody = "block_body" KindBlockParameter = "block_parameter" KindBlockParameters = "block_parameters" KindBodyStatement = "body_statement" KindBreak = "break" KindCall = "call" KindCase = "case" KindCaseMatch = "case_match" KindChainedString = "chained_string" KindCharacter = "character" KindClass = "class" KindClassVariable = "class_variable" KindComment = "comment" KindComplex = "complex" KindConditional = "conditional" KindConstant = "constant" KindDelimitedSymbol = "delimited_symbol" KindDestructuredLeftAssignment = "destructured_left_assignment" KindDestructuredParameter = "destructured_parameter" KindDo = "do" KindDoBlock = "do_block" KindElementReference = "element_reference" KindElse = "else" KindElsif = "elsif" KindEmptyStatement = "empty_statement" KindEncoding = "encoding" KindEndBlock = "end_block" KindEnsure = "ensure" KindEscapeSequence = "escape_sequence" KindExceptionVariable = "exception_variable" KindExceptions = "exceptions" KindExpressionReferencePattern = "expression_reference_pattern" KindFalse = "false" KindFile = "file" KindFindPattern = "find_pattern" KindFloat = "float" KindFor = "for" KindForwardArgument = "forward_argument" KindForwardParameter = "forward_parameter" KindGlobalVariable = "global_variable" KindHash = "hash" KindHashKeySymbol = "hash_key_symbol" KindHashPattern = "hash_pattern" KindHashSplatArgument = "hash_splat_argument" KindHashSplatNil = "hash_splat_nil" KindHashSplatParameter = "hash_splat_parameter" KindHeredocBeginning = "heredoc_beginning" KindHeredocBody = "heredoc_body" KindHeredocContent = "heredoc_content" KindHeredocEnd = "heredoc_end" KindIdentifier = "identifier" KindIf = "if" KindIfGuard = "if_guard" KindIfModifier = "if_modifier" KindIn = "in" KindInClause = "in_clause" KindInstanceVariable = "instance_variable" KindInteger = "integer" KindInterpolation = "interpolation" KindKeywordParameter = "keyword_parameter" KindKeywordPattern = "keyword_pattern" KindLambda = "lambda" KindLambdaParameters = "lambda_parameters" KindLeftAssignmentList = "left_assignment_list" KindLine = "line" KindMatchPattern = "match_pattern" KindMethod = "method" KindMethodParameters = "method_parameters" KindModule = "module" KindNext = "next" KindNil = "nil" KindOperator = "operator" KindOperatorAssignment = "operator_assignment" KindOptionalParameter = "optional_parameter" KindPair = "pair" KindParenthesizedPattern = "parenthesized_pattern" KindParenthesizedStatements = "parenthesized_statements" KindPattern = "pattern" KindProgram = "program" KindRange = "range" KindRational = "rational" KindRedo = "redo" KindRegex = "regex" KindRescue = "rescue" KindRescueModifier = "rescue_modifier" KindRestAssignment = "rest_assignment" KindRetry = "retry" KindReturn = "return" KindRightAssignmentList = "right_assignment_list" KindScopeResolution = "scope_resolution" KindSelf = "self" KindSetter = "setter" KindSimpleSymbol = "simple_symbol" KindSingletonClass = "singleton_class" KindSingletonMethod = "singleton_method" KindSplatArgument = "splat_argument" KindSplatParameter = "splat_parameter" KindString = "string" KindStringArray = "string_array" KindStringContent = "string_content" KindSubshell = "subshell" KindSuper = "super" KindSuperclass = "superclass" KindSymbolArray = "symbol_array" KindTestPattern = "test_pattern" KindThen = "then" KindTrue = "true" KindUnary = "unary" KindUndef = "undef" KindUninterpreted = "uninterpreted" KindUnless = "unless" KindUnlessGuard = "unless_guard" KindUnlessModifier = "unless_modifier" KindUntil = "until" KindUntilModifier = "until_modifier" KindVariableReferencePattern = "variable_reference_pattern" KindWhen = "when" KindWhile = "while" KindWhileModifier = "while_modifier" KindYield = "yield" )
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" FieldAlternatives = "alternatives" FieldArguments = "arguments" FieldBegin = "begin" FieldBlock = "block" FieldBody = "body" FieldClass = "class" FieldClauses = "clauses" FieldCondition = "condition" FieldConsequence = "consequence" FieldElse = "else" FieldEnd = "end" FieldExceptions = "exceptions" FieldGuard = "guard" FieldHandler = "handler" FieldKey = "key" FieldLeft = "left" FieldLocals = "locals" FieldMethod = "method" FieldName = "name" FieldObject = "object" FieldOperand = "operand" FieldOperator = "operator" FieldParameters = "parameters" FieldPattern = "pattern" FieldReceiver = "receiver" FieldRight = "right" FieldScope = "scope" FieldSuperclass = "superclass" FieldValue = "value" FieldVariable = "variable" )
FieldX constants name every field this grammar attaches to child nodes, for Node.ChildByField and Node.Field.
const GrammarVersion = "v0.23.1"
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 = 33
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-ruby.git @ v0.23.1) 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()