tree_sitter_language_pack 1.6.2-aarch64-linux → 1.8.0-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95f119e809729eb6b4ac0ea5d504587098a8e2704ad98bafa25e5132f48b2186
4
- data.tar.gz: 2663d7c69607f686fc12bd5e29cd81b8de649e9c54bfb644d8a3113c966a238d
3
+ metadata.gz: 2e72dc0757d8ce3712c76c57520f8d46df9da350bffcb31cbbc038726313d256
4
+ data.tar.gz: 5632e0484c40c1bfc535cdf1680c8013f3ac85fc7fb000f0393229c9c0237306
5
5
  SHA512:
6
- metadata.gz: 2255dfcd30617901786e57a4ab5e095708878896d76e6bcdcd6126bb664b0240f8960b272da60061e3a3628cdfb116d89a885d91897355f60d5fccedf662fbfe
7
- data.tar.gz: d531ea83ca585d66b9a6abd95c3032f0601927afa4a649351755550ea0489069d5cb2f075bc48ea877116f8ae0905ea3d5a75dc455346c81c4a0212edeac8069
6
+ metadata.gz: 806edc514539455973c47f17c78c9a58862a399412323aa861aa2867d9f5a4a44ca9c154adce10cc8109a7d10583c31b189851331b1a09b26db8f47e5a4c66dc
7
+ data.tar.gz: 37ed38d03056faa12b112999b19c3ea546ae0f15f9ae7f5ce8edb47ced63c32460c2857da3d94d604b27587c2ddeb80955cb9cf0b8b4748b0759823c057fdbdb
data/Steepfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ signature 'sig'
5
+ check 'lib'
6
+ end
@@ -0,0 +1,46 @@
1
+ # This file is auto-generated by alef — DO NOT EDIT.
2
+ # alef:hash:f1cee06ff8900ef2d958db4c1c0a5cb8d233243dfa3834f678c826f070dc817d
3
+ # To regenerate: alef generate
4
+ # To verify freshness: alef verify --exit-code
5
+ # Issues & docs: https://github.com/kreuzberg-dev/alef
6
+ # frozen_string_literal: true
7
+
8
+ require 'json'
9
+ require 'ts_pack_core_rb'
10
+
11
+ # Add accessor methods to Hash-based internally-tagged enum instances
12
+ class Hash
13
+ # Support internally-tagged enum accessors like format.excel, format.email, etc.
14
+ # Also support direct field access like format.sheet_count
15
+ # rubocop:disable Metrics/CyclomaticComplexity
16
+ def method_missing(method_name, *args, &)
17
+ # Try symbol key first (how Magnus converts JSON keys)
18
+ return self[method_name] if key?(method_name)
19
+
20
+ # Try string key
21
+ return self[method_name.to_s] if key?(method_name.to_s)
22
+
23
+ # Check if this hash has a 'format_type' field (indicating an internally-tagged enum)
24
+ format_type = self[:format_type] || self['format_type']
25
+ return super unless format_type
26
+
27
+ # If the method name matches the format_type (snake_case), extract and return the variant's wrapped data
28
+ # Internally-tagged enums store variant data in the '_0' field (from alef's struct variant conversion)
29
+ # This allows format.excel to return the ExcelMetadata hash with sheet_count, sheet_names, etc.
30
+ snake_case_method = method_name.to_s.downcase
31
+ return self[:_0] || self['_0'] || self if snake_case_method == format_type.to_s.downcase
32
+
33
+ super
34
+ end
35
+ # rubocop:enable Metrics/CyclomaticComplexity
36
+
37
+ def respond_to_missing?(method_name, include_private = false)
38
+ return true if key?(method_name) || key?(method_name.to_s)
39
+
40
+ format_type = self[:format_type] || self['format_type']
41
+ return false unless format_type
42
+
43
+ snake_case_method = method_name.to_s.downcase
44
+ snake_case_method == format_type.to_s.downcase || super
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ # This file is auto-generated by alef — DO NOT EDIT.
2
+ # alef:hash:2780c47ba4a676fb85ddbc11c9e7bb4f659e63c0b90affd517b29c7cde7a84aa
3
+ # To regenerate: alef generate
4
+ # To verify freshness: alef verify --exit-code
5
+ # Issues & docs: https://github.com/kreuzberg-dev/alef
6
+ # frozen_string_literal: true
7
+
8
+ module TreeSitterLanguagePack
9
+ VERSION = '1.8.0'
10
+ end
@@ -1,7 +1,13 @@
1
+ # This file is auto-generated by alef — DO NOT EDIT.
2
+ # alef:hash:d6b009b67f6b2b81396e42b3a3a93d5a0ad50e680621fbda45fed6329de157df
3
+ # To regenerate: alef generate
4
+ # To verify freshness: alef verify --exit-code
5
+ # Issues & docs: https://github.com/kreuzberg-dev/alef
1
6
  # frozen_string_literal: true
2
7
 
3
- require_relative 'tree_sitter_language_pack/ts_pack_ruby'
8
+ require_relative 'tree_sitter_language_pack/version'
9
+ require_relative 'tree_sitter_language_pack/native'
4
10
 
5
- # Ruby bindings for the tree-sitter language pack.
6
11
  module TreeSitterLanguagePack
12
+ # Re-export all types and functions from native extension
7
13
  end
data/sig/types.rbs ADDED
@@ -0,0 +1,433 @@
1
+ # This file is auto-generated by alef — DO NOT EDIT.
2
+ # alef:hash:3cbc9b7f5a084fe4fe656040ca379c3bbdd7a966ad4403cba58d0411a75cce07
3
+ # To regenerate: alef generate
4
+ # To verify freshness: alef verify --exit-code
5
+ # Issues & docs: https://github.com/kreuzberg-dev/alef
6
+
7
+ module TreeSitterLanguagePack
8
+
9
+ VERSION: String
10
+
11
+ class Span
12
+ # Byte and line/column range in source code.
13
+ #
14
+ # Represents both byte offsets (for slicing) and human-readable line/column
15
+ # positions (for display and diagnostics).
16
+
17
+ attr_accessor start_byte: Integer?
18
+ attr_accessor end_byte: Integer?
19
+ attr_accessor start_line: Integer?
20
+ attr_accessor start_column: Integer?
21
+ attr_accessor end_line: Integer?
22
+ attr_accessor end_column: Integer?
23
+
24
+ def initialize: (start_byte: Integer, end_byte: Integer, start_line: Integer, start_column: Integer, end_line: Integer, end_column: Integer) -> void
25
+ end
26
+
27
+ class ProcessResult
28
+ # Complete analysis result from processing a source file.
29
+ #
30
+ # Contains metrics, structural analysis, imports/exports, comments,
31
+ # docstrings, symbols, diagnostics, and optionally chunked code segments.
32
+ # Fields are populated based on the `ProcessConfig` flags.
33
+ #
34
+ # # Fields
35
+ #
36
+ # - `language` - The language used for parsing
37
+ # - `metrics` - Always computed: line counts, byte sizes, error counts
38
+ # - `structure` - Functions, classes, structs (when `config.structure = true`)
39
+ # - `imports` - Import statements (when `config.imports = true`)
40
+ # - `exports` - Export statements (when `config.exports = true`)
41
+ # - `comments` - Comments (when `config.comments = true`)
42
+ # - `docstrings` - Docstrings (when `config.docstrings = true`)
43
+ # - `symbols` - Symbol definitions (when `config.symbols = true`)
44
+ # - `diagnostics` - Parse errors (when `config.diagnostics = true`)
45
+ # - `chunks` - Chunked code segments (when `config.chunk_max_size` is set)
46
+
47
+ attr_accessor language: String?
48
+ attr_accessor metrics: FileMetrics?
49
+ attr_accessor structure: Array[StructureItem]?
50
+ attr_accessor imports: Array[ImportInfo]?
51
+ attr_accessor exports: Array[ExportInfo]?
52
+ attr_accessor comments: Array[CommentInfo]?
53
+ attr_accessor docstrings: Array[DocstringInfo]?
54
+ attr_accessor symbols: Array[SymbolInfo]?
55
+ attr_accessor diagnostics: Array[Diagnostic]?
56
+ attr_accessor chunks: Array[CodeChunk]?
57
+
58
+ def initialize: (language: String, metrics: FileMetrics, structure: Array[StructureItem], imports: Array[ImportInfo], exports: Array[ExportInfo], comments: Array[CommentInfo], docstrings: Array[DocstringInfo], symbols: Array[SymbolInfo], diagnostics: Array[Diagnostic], chunks: Array[CodeChunk]) -> void
59
+ end
60
+
61
+ class FileMetrics
62
+ # Aggregate metrics for a source file.
63
+
64
+ attr_accessor total_lines: Integer?
65
+ attr_accessor code_lines: Integer?
66
+ attr_accessor comment_lines: Integer?
67
+ attr_accessor blank_lines: Integer?
68
+ attr_accessor total_bytes: Integer?
69
+ attr_accessor node_count: Integer?
70
+ attr_accessor error_count: Integer?
71
+ attr_accessor max_depth: Integer?
72
+
73
+ def initialize: (total_lines: Integer, code_lines: Integer, comment_lines: Integer, blank_lines: Integer, total_bytes: Integer, node_count: Integer, error_count: Integer, max_depth: Integer) -> void
74
+ end
75
+
76
+ class StructureItem
77
+ # A structural item (function, class, struct, etc.) in source code.
78
+
79
+ attr_accessor kind: StructureKind?
80
+ attr_accessor name: String?
81
+ attr_accessor visibility: String?
82
+ attr_accessor span: Span?
83
+ attr_accessor children: Array[StructureItem]?
84
+ attr_accessor decorators: Array[String]?
85
+ attr_accessor doc_comment: String?
86
+ attr_accessor signature: String?
87
+ attr_accessor body_span: Span?
88
+
89
+ def initialize: (kind: StructureKind, ?name: String, ?visibility: String, span: Span, children: Array[StructureItem], decorators: Array[String], ?doc_comment: String, ?signature: String, ?body_span: Span) -> void
90
+ end
91
+
92
+ class CommentInfo
93
+ # A comment extracted from source code.
94
+
95
+ attr_accessor text: String?
96
+ attr_accessor kind: CommentKind?
97
+ attr_accessor span: Span?
98
+ attr_accessor associated_node: String?
99
+
100
+ def initialize: (text: String, kind: CommentKind, span: Span, ?associated_node: String) -> void
101
+ end
102
+
103
+ class DocstringInfo
104
+ # A docstring extracted from source code.
105
+
106
+ attr_accessor text: String?
107
+ attr_accessor format: DocstringFormat?
108
+ attr_accessor span: Span?
109
+ attr_accessor associated_item: String?
110
+ attr_accessor parsed_sections: Array[DocSection]?
111
+
112
+ def initialize: (text: String, format: DocstringFormat, span: Span, ?associated_item: String, parsed_sections: Array[DocSection]) -> void
113
+ end
114
+
115
+ class DocSection
116
+ # A section within a docstring (e.g., Args, Returns, Raises).
117
+
118
+ attr_accessor kind: String?
119
+ attr_accessor name: String?
120
+ attr_accessor description: String?
121
+
122
+ def initialize: (kind: String, ?name: String, description: String) -> void
123
+ end
124
+
125
+ class ImportInfo
126
+ # An import statement extracted from source code.
127
+
128
+ attr_accessor source: String?
129
+ attr_accessor items: Array[String]?
130
+ attr_accessor alias: String?
131
+ attr_accessor is_wildcard: bool?
132
+ attr_accessor span: Span?
133
+
134
+ def initialize: (source: String, items: Array[String], ?alias: String, is_wildcard: bool, span: Span) -> void
135
+ end
136
+
137
+ class ExportInfo
138
+ # An export statement extracted from source code.
139
+
140
+ attr_accessor name: String?
141
+ attr_accessor kind: ExportKind?
142
+ attr_accessor span: Span?
143
+
144
+ def initialize: (name: String, kind: ExportKind, span: Span) -> void
145
+ end
146
+
147
+ class SymbolInfo
148
+ # A symbol (variable, function, type, etc.) extracted from source code.
149
+
150
+ attr_accessor name: String?
151
+ attr_accessor kind: SymbolKind?
152
+ attr_accessor span: Span?
153
+ attr_accessor type_annotation: String?
154
+ attr_accessor doc: String?
155
+
156
+ def initialize: (name: String, kind: SymbolKind, span: Span, ?type_annotation: String, ?doc: String) -> void
157
+ end
158
+
159
+ class Diagnostic
160
+ # A diagnostic (syntax error, missing node, etc.) from parsing.
161
+
162
+ attr_accessor message: String?
163
+ attr_accessor severity: DiagnosticSeverity?
164
+ attr_accessor span: Span?
165
+
166
+ def initialize: (message: String, severity: DiagnosticSeverity, span: Span) -> void
167
+ end
168
+
169
+ class CodeChunk
170
+ # A chunk of source code with rich metadata.
171
+
172
+ attr_accessor content: String?
173
+ attr_accessor start_byte: Integer?
174
+ attr_accessor end_byte: Integer?
175
+ attr_accessor start_line: Integer?
176
+ attr_accessor end_line: Integer?
177
+ attr_accessor metadata: ChunkContext?
178
+
179
+ def initialize: (content: String, start_byte: Integer, end_byte: Integer, start_line: Integer, end_line: Integer, metadata: ChunkContext) -> void
180
+ end
181
+
182
+ class ChunkContext
183
+ # Metadata for a single chunk of source code.
184
+
185
+ attr_accessor language: String?
186
+ attr_accessor chunk_index: Integer?
187
+ attr_accessor total_chunks: Integer?
188
+ attr_accessor node_types: Array[String]?
189
+ attr_accessor context_path: Array[String]?
190
+ attr_accessor symbols_defined: Array[String]?
191
+ attr_accessor comments: Array[CommentInfo]?
192
+ attr_accessor docstrings: Array[DocstringInfo]?
193
+ attr_accessor has_error_nodes: bool?
194
+
195
+ def initialize: (language: String, chunk_index: Integer, total_chunks: Integer, node_types: Array[String], context_path: Array[String], symbols_defined: Array[String], comments: Array[CommentInfo], docstrings: Array[DocstringInfo], has_error_nodes: bool) -> void
196
+ end
197
+
198
+ class PackConfig
199
+ # Configuration for the tree-sitter language pack.
200
+ #
201
+ # Controls cache directory and which languages to pre-download.
202
+ # Can be loaded from a TOML file, constructed programmatically,
203
+ # or passed as a dict/object from language bindings.
204
+ #
205
+ # # Example
206
+ #
207
+ # ```no_run
208
+ # use tree_sitter_language_pack::PackConfig;
209
+ #
210
+ # let config = PackConfig {
211
+ # cache_dir: None,
212
+ # languages: Some(vec!["python".to_string(), "rust".to_string()]),
213
+ # groups: None,
214
+ # };
215
+ # ```
216
+
217
+ attr_accessor cache_dir: String?
218
+ attr_accessor languages: Array[String]?
219
+ attr_accessor groups: Array[String]?
220
+
221
+ def initialize: (?cache_dir: String, ?languages: Array[String], ?groups: Array[String]) -> void
222
+ def self.from_toml_file: (String path) -> PackConfig
223
+ def self.discover: () -> PackConfig?
224
+ end
225
+
226
+ class ProcessConfig
227
+ # Configuration for the `process()` function.
228
+ #
229
+ # Controls which analysis features are enabled and whether chunking is performed.
230
+ #
231
+ # # Examples
232
+ #
233
+ # ```
234
+ # use tree_sitter_language_pack::ProcessConfig;
235
+ #
236
+ # // Defaults: structure + imports + exports enabled
237
+ # let config = ProcessConfig::new("python");
238
+ #
239
+ # // With chunking
240
+ # let config = ProcessConfig::new("python").with_chunking(1000);
241
+ #
242
+ # // Everything enabled
243
+ # let config = ProcessConfig::new("python").all();
244
+ # ```
245
+
246
+ attr_accessor language: String?
247
+ attr_accessor structure: bool?
248
+ attr_accessor imports: bool?
249
+ attr_accessor exports: bool?
250
+ attr_accessor comments: bool?
251
+ attr_accessor docstrings: bool?
252
+ attr_accessor symbols: bool?
253
+ attr_accessor diagnostics: bool?
254
+ attr_accessor chunk_max_size: Integer?
255
+
256
+ def initialize: (language: String, structure: bool, imports: bool, exports: bool, comments: bool, docstrings: bool, symbols: bool, diagnostics: bool, ?chunk_max_size: Integer) -> void
257
+ def with_chunking: (Integer max_size) -> ProcessConfig
258
+ def all: () -> ProcessConfig
259
+ def minimal: () -> ProcessConfig
260
+ def self.default: () -> ProcessConfig
261
+ end
262
+
263
+ class LanguageRegistry
264
+ # Thread-safe registry of tree-sitter language parsers.
265
+ #
266
+ # Manages both statically compiled and dynamically loaded language grammars.
267
+ # Use [`LanguageRegistry::new()`] for the default registry, or access the
268
+ # global instance via the module-level convenience functions
269
+ # (`get_language`, `available_languages`, etc.).
270
+ #
271
+ # # Example
272
+ #
273
+ # ```no_run
274
+ # use tree_sitter_language_pack::{LanguageRegistry, ProcessConfig};
275
+ #
276
+ # let registry = LanguageRegistry::new();
277
+ # let langs = registry.available_languages();
278
+ # println!("Available: {:?}", langs);
279
+ #
280
+ # let config = ProcessConfig::new("python").all();
281
+ # let result = registry.process("def hello(): pass", &config).unwrap();
282
+ # println!("Structure: {:?}", result.structure);
283
+ # ```
284
+
285
+ def add_extra_libs_dir: (String dir) -> void
286
+ def get_language: (String name) -> Language
287
+ def available_languages: () -> Array[String]
288
+ def has_language: (String name) -> bool
289
+ def language_count: () -> Integer
290
+ def process: (String source, ProcessConfig config) -> ProcessResult
291
+ def self.with_libs_dir: (String libs_dir) -> LanguageRegistry
292
+ def self.default: () -> LanguageRegistry
293
+ end
294
+
295
+ class ParserManifest
296
+ # Manifest describing available parser downloads for a specific version.
297
+
298
+ attr_reader version: String
299
+ attr_reader platforms: Hash[String, PlatformBundle]
300
+ attr_reader languages: Hash[String, LanguageInfo]
301
+ attr_reader groups: Hash[String, Array[String]]
302
+
303
+ def initialize: (version: String, platforms: Hash[String, PlatformBundle], languages: Hash[String, LanguageInfo], groups: Hash[String, Array[String]]) -> void
304
+ end
305
+
306
+ class PlatformBundle
307
+ attr_reader url: String
308
+ attr_reader sha256: String
309
+ attr_reader size: Integer
310
+
311
+ def initialize: (url: String, sha256: String, size: Integer) -> void
312
+ end
313
+
314
+ class LanguageInfo
315
+ attr_reader group: String
316
+ attr_reader size: Integer
317
+
318
+ def initialize: (group: String, size: Integer) -> void
319
+ end
320
+
321
+ class DownloadManager
322
+ # Manages downloading and caching of pre-built parser shared libraries.
323
+
324
+ def cache_dir: () -> String
325
+ def installed_languages: () -> Array[String]
326
+ def ensure_languages: (Array[String] names) -> void
327
+ def ensure_group: (String group) -> void
328
+ def lib_path: (String name) -> String
329
+ def fetch_manifest: () -> ParserManifest
330
+ def download_all_best_effort: () -> Integer
331
+ def clean_cache: () -> void
332
+ def self.new: (String version) -> DownloadManager
333
+ def self.with_cache_dir: (String version, String cache_dir) -> DownloadManager
334
+ def self.default_cache_dir: (String version) -> String
335
+ end
336
+
337
+ class Language
338
+ end
339
+
340
+ class Parser
341
+ end
342
+
343
+ class Tree
344
+ end
345
+
346
+ class StructureKind
347
+ # The kind of structural item found in source code.
348
+ #
349
+ # Categorizes top-level and nested declarations such as functions, classes,
350
+ # structs, enums, traits, and more. Use [`Other`](StructureKind::Other) for
351
+ # language-specific constructs that do not fit a standard category.
352
+ end
353
+
354
+ class CommentKind
355
+ # The kind of a comment found in source code.
356
+ #
357
+ # Distinguishes between single-line comments, block (multi-line) comments,
358
+ # and documentation comments.
359
+ type instance = :line | :block | :doc
360
+ end
361
+
362
+ class DocstringFormat
363
+ # The format of a docstring extracted from source code.
364
+ #
365
+ # Identifies the docstring convention used, which varies by language
366
+ # (e.g., Python triple-quoted strings, JSDoc, Rustdoc `///` comments).
367
+ end
368
+
369
+ class ExportKind
370
+ # The kind of an export statement found in source code.
371
+ #
372
+ # Covers named exports, default exports, and re-exports from other modules.
373
+ type instance = :named | :default | :re_export
374
+ end
375
+
376
+ class SymbolKind
377
+ # The kind of a symbol definition found in source code.
378
+ #
379
+ # Categorizes symbol definitions such as variables, constants, functions,
380
+ # classes, types, interfaces, enums, and modules.
381
+ end
382
+
383
+ class DiagnosticSeverity
384
+ # Severity level of a diagnostic produced during parsing.
385
+ #
386
+ # Used to classify parse errors, warnings, and informational messages
387
+ # found in the syntax tree.
388
+ type instance = :error | :warning | :info
389
+ end
390
+
391
+ def self.detect_language_from_extension: (String ext) -> String?
392
+
393
+ def self.detect_language_from_path: (String path) -> String?
394
+
395
+ def self.detect_language_from_content: (String content) -> String?
396
+
397
+ def self.get_highlights_query: (String language) -> String?
398
+
399
+ def self.get_injections_query: (String language) -> String?
400
+
401
+ def self.get_locals_query: (String language) -> String?
402
+
403
+ def self.get_language: (String name) -> Language
404
+
405
+ def self.get_parser: (String name) -> Parser
406
+
407
+ def self.detect_language: (String path) -> String?
408
+
409
+ def self.available_languages: () -> Array[String]
410
+
411
+ def self.has_language: (String name) -> bool
412
+
413
+ def self.language_count: () -> Integer
414
+
415
+ def self.process: (String source, ProcessConfig config) -> ProcessResult
416
+
417
+ def self.init: (PackConfig config) -> void
418
+
419
+ def self.configure: (PackConfig config) -> void
420
+
421
+ def self.download: (Array[String] names) -> Integer
422
+
423
+ def self.download_all: () -> Integer
424
+
425
+ def self.manifest_languages: () -> Array[String]
426
+
427
+ def self.downloaded_languages: () -> Array[String]
428
+
429
+ def self.clean_cache: () -> void
430
+
431
+ def self.cache_dir: () -> String
432
+
433
+ end
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_sitter_language_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.8.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
- - kreuzberg.dev
7
+ - Kreuzberg Team
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: 305 pre-compiled tree-sitter language parsers with Ruby bindings via
13
- Magnus native extensions.
14
- email:
15
- - dev@kreuzberg.dev
12
+ description: Pre-compiled tree-sitter grammars for 305 programming languages
16
13
  executables: []
17
14
  extensions: []
18
15
  extra_rdoc_files: []
19
16
  files:
20
- - Cargo.toml
17
+ - Steepfile
21
18
  - lib/tree_sitter_language_pack.rb
22
- - lib/tree_sitter_language_pack/ts_pack_ruby.so
23
- - src/lib.rs
19
+ - lib/tree_sitter_language_pack/native.rb
20
+ - lib/tree_sitter_language_pack/version.rb
21
+ - lib/ts_pack_core_rb.so
22
+ - sig/types.rbs
24
23
  homepage: https://github.com/kreuzberg-dev/tree-sitter-language-pack
25
24
  licenses:
26
25
  - MIT
27
26
  metadata:
28
- cargo_crate_name: ts-pack-ruby
27
+ keywords: tree-sitter,parser,syntax,language-pack
28
+ rubygems_mfa_required: 'true'
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
@@ -33,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 3.4.0
36
+ version: 3.2.0
37
37
  required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
@@ -42,5 +42,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  requirements: []
43
43
  rubygems_version: 3.6.9
44
44
  specification_version: 4
45
- summary: Ruby bindings for tree-sitter-language-pack
45
+ summary: Pre-compiled tree-sitter grammars for 305 programming languages
46
46
  test_files: []
data/Cargo.toml DELETED
@@ -1,22 +0,0 @@
1
- [package]
2
- name = "ts-pack-ruby"
3
- version.workspace = true
4
- edition.workspace = true
5
- license.workspace = true
6
- repository.workspace = true
7
- description = "Ruby Magnus bindings for tree-sitter language pack"
8
- publish = false
9
-
10
- [package.metadata.cargo-machete]
11
- ignored = ["rb-sys"]
12
-
13
- [lib]
14
- name = "ts_pack_ruby"
15
- crate-type = ["cdylib"]
16
-
17
- [dependencies]
18
- magnus = "0.8"
19
- rb-sys = "0.9"
20
- serde_json = { workspace = true }
21
- tree-sitter = { workspace = true }
22
- tree-sitter-language-pack = { workspace = true, features = ["serde", "download"] }
data/src/lib.rs DELETED
@@ -1,296 +0,0 @@
1
- use magnus::{Error, IntoValue, Ruby, Value as RbValue, function, method, prelude::*};
2
- use std::sync::Mutex;
3
-
4
- /// Wraps a tree-sitter Tree for safe sharing across the Ruby boundary.
5
- #[magnus::wrap(class = "TreeSitterLanguagePack::Tree")]
6
- struct TreeWrapper(Mutex<tree_sitter::Tree>);
7
-
8
- /// Helper to create a runtime error from instance methods where `&Ruby` is not available.
9
- fn lock_error() -> Error {
10
- // SAFETY: This is called from Ruby-invoked methods, so the Ruby VM is active.
11
- let ruby = unsafe { Ruby::get_unchecked() };
12
- Error::new(ruby.exception_runtime_error(), "lock poisoned")
13
- }
14
-
15
- impl TreeWrapper {
16
- fn root_node_type(&self) -> Result<String, Error> {
17
- let guard = self.0.lock().map_err(|_| lock_error())?;
18
- Ok(guard.root_node().kind().to_string())
19
- }
20
-
21
- fn root_child_count(&self) -> Result<usize, Error> {
22
- let guard = self.0.lock().map_err(|_| lock_error())?;
23
- Ok(guard.root_node().named_child_count())
24
- }
25
-
26
- fn contains_node_type(&self, node_type: String) -> Result<bool, Error> {
27
- let guard = self.0.lock().map_err(|_| lock_error())?;
28
- Ok(tree_sitter_language_pack::tree_contains_node_type(&guard, &node_type))
29
- }
30
-
31
- fn has_error_nodes(&self) -> Result<bool, Error> {
32
- let guard = self.0.lock().map_err(|_| lock_error())?;
33
- Ok(tree_sitter_language_pack::tree_has_error_nodes(&guard))
34
- }
35
- }
36
-
37
- fn available_languages() -> Vec<String> {
38
- tree_sitter_language_pack::available_languages()
39
- }
40
-
41
- fn has_language(name: String) -> bool {
42
- tree_sitter_language_pack::has_language(&name)
43
- }
44
-
45
- fn detect_language(path: String) -> Option<String> {
46
- tree_sitter_language_pack::detect_language_from_path(&path).map(String::from)
47
- }
48
-
49
- fn detect_language_from_content(content: String) -> Option<String> {
50
- tree_sitter_language_pack::detect_language_from_content(&content).map(String::from)
51
- }
52
-
53
- fn detect_language_from_extension(ext: String) -> Option<String> {
54
- tree_sitter_language_pack::detect_language_from_extension(&ext).map(String::from)
55
- }
56
-
57
- fn detect_language_from_path(path: String) -> Option<String> {
58
- tree_sitter_language_pack::detect_language_from_path(&path).map(String::from)
59
- }
60
-
61
- /// Returns extension ambiguity information as a JSON string, or nil.
62
- fn extension_ambiguity(ext: String) -> Option<String> {
63
- tree_sitter_language_pack::extension_ambiguity_json(&ext)
64
- }
65
-
66
- fn get_highlights_query(language: String) -> Option<String> {
67
- tree_sitter_language_pack::get_highlights_query(&language).map(String::from)
68
- }
69
-
70
- fn get_injections_query(language: String) -> Option<String> {
71
- tree_sitter_language_pack::get_injections_query(&language).map(String::from)
72
- }
73
-
74
- fn get_locals_query(language: String) -> Option<String> {
75
- tree_sitter_language_pack::get_locals_query(&language).map(String::from)
76
- }
77
-
78
- fn language_count() -> usize {
79
- tree_sitter_language_pack::language_count()
80
- }
81
-
82
- fn get_language_ptr(ruby: &Ruby, name: String) -> Result<u64, Error> {
83
- let language = tree_sitter_language_pack::get_language(&name)
84
- .map_err(|_| Error::new(ruby.exception_runtime_error(), format!("language not found: {name}")))?;
85
- let raw_ptr = language.into_raw();
86
- Ok(raw_ptr as u64)
87
- }
88
-
89
- fn parse_string(ruby: &Ruby, language: String, source: String) -> Result<TreeWrapper, Error> {
90
- let tree = tree_sitter_language_pack::parse_string(&language, source.as_bytes())
91
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
92
- Ok(TreeWrapper(Mutex::new(tree)))
93
- }
94
-
95
- /// Convert a serde_json::Value to a native Ruby object (Hash, Array, String, Integer, Float, true/false, nil).
96
- fn json_value_to_ruby(ruby: &Ruby, value: &serde_json::Value) -> Result<RbValue, Error> {
97
- Ok(match value {
98
- serde_json::Value::Null => ruby.qnil().as_value(),
99
- serde_json::Value::Bool(b) => (*b).into_value_with(ruby),
100
- serde_json::Value::Number(n) => {
101
- if let Some(i) = n.as_i64() {
102
- i.into_value_with(ruby)
103
- } else if let Some(u) = n.as_u64() {
104
- u.into_value_with(ruby)
105
- } else if let Some(f) = n.as_f64() {
106
- f.into_value_with(ruby)
107
- } else {
108
- ruby.qnil().as_value()
109
- }
110
- }
111
- serde_json::Value::String(s) => s.as_str().into_value_with(ruby),
112
- serde_json::Value::Array(arr) => {
113
- let ary = ruby.ary_new_capa(arr.len());
114
- for item in arr {
115
- ary.push(json_value_to_ruby(ruby, item)?)?;
116
- }
117
- ary.as_value()
118
- }
119
- serde_json::Value::Object(map) => {
120
- let hash = ruby.hash_new();
121
- for (k, v) in map {
122
- hash.aset(k.as_str(), json_value_to_ruby(ruby, v)?)?;
123
- }
124
- hash.as_value()
125
- }
126
- })
127
- }
128
-
129
- /// Unified process method that accepts a JSON config string and returns a native Ruby Hash.
130
- ///
131
- /// The config JSON must contain at least `"language"`. Optional fields:
132
- /// - `structure`, `imports`, `exports`, `comments`, `docstrings`, `symbols`, `diagnostics` (booleans, default true)
133
- /// - `chunk_max_size` (integer or null, default null meaning no chunking)
134
- fn process(ruby: &Ruby, source: String, config_json: String) -> Result<RbValue, Error> {
135
- let core_config: tree_sitter_language_pack::ProcessConfig = serde_json::from_str(&config_json)
136
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
137
-
138
- let result = tree_sitter_language_pack::process(&source, &core_config)
139
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
140
-
141
- let json_value = serde_json::to_value(&result)
142
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))?;
143
- json_value_to_ruby(ruby, &json_value)
144
- }
145
-
146
- /// Extract patterns from source code using a JSON configuration.
147
- ///
148
- /// The config JSON must contain:
149
- /// - `language` (string): the language name
150
- /// - `patterns` (object): named patterns to run, each with a `query` field
151
- ///
152
- /// Returns a native Ruby Hash with extraction results.
153
- fn extract(ruby: &Ruby, source: String, config_json: String) -> Result<RbValue, Error> {
154
- let config: tree_sitter_language_pack::ExtractionConfig = serde_json::from_str(&config_json)
155
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
156
-
157
- let result = tree_sitter_language_pack::extract_patterns(&source, &config)
158
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
159
-
160
- let json_value = serde_json::to_value(&result)
161
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))?;
162
- json_value_to_ruby(ruby, &json_value)
163
- }
164
-
165
- /// Validate extraction patterns without running them.
166
- ///
167
- /// The config JSON must contain:
168
- /// - `language` (string): the language name
169
- /// - `patterns` (object): named patterns to validate
170
- ///
171
- /// Returns a native Ruby Hash with validation results.
172
- fn validate_extraction(ruby: &Ruby, config_json: String) -> Result<RbValue, Error> {
173
- let config: tree_sitter_language_pack::ExtractionConfig = serde_json::from_str(&config_json)
174
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
175
-
176
- let result = tree_sitter_language_pack::validate_extraction(&config)
177
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
178
-
179
- let json_value = serde_json::to_value(&result)
180
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))?;
181
- json_value_to_ruby(ruby, &json_value)
182
- }
183
-
184
- /// Initialize the language pack with configuration.
185
- ///
186
- /// Accepts a JSON string with optional fields:
187
- /// - `cache_dir` (string): override default cache directory
188
- /// - `languages` (array): language names to pre-download
189
- /// - `groups` (array): language groups to pre-download
190
- fn rb_init(ruby: &Ruby, config_json: String) -> Result<(), Error> {
191
- let config: tree_sitter_language_pack::PackConfig = serde_json::from_str(&config_json)
192
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
193
-
194
- tree_sitter_language_pack::init(&config).map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
195
- }
196
-
197
- /// Configure the language pack without downloading.
198
- ///
199
- /// Accepts a JSON string with optional fields:
200
- /// - `cache_dir` (string): override default cache directory
201
- fn rb_configure(ruby: &Ruby, config_json: String) -> Result<(), Error> {
202
- let config: tree_sitter_language_pack::PackConfig = serde_json::from_str(&config_json)
203
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
204
-
205
- tree_sitter_language_pack::configure(&config)
206
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
207
- }
208
-
209
- /// Download specific languages to the cache.
210
- ///
211
- /// Returns the number of newly downloaded languages.
212
- fn rb_download(ruby: &Ruby, names: Vec<String>) -> Result<usize, Error> {
213
- let refs: Vec<&str> = names.iter().map(String::as_str).collect();
214
- tree_sitter_language_pack::download(&refs).map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
215
- }
216
-
217
- /// Download all available languages from the remote manifest.
218
- ///
219
- /// Returns the number of newly downloaded languages.
220
- fn rb_download_all(ruby: &Ruby) -> Result<usize, Error> {
221
- tree_sitter_language_pack::download_all().map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
222
- }
223
-
224
- /// Get all language names available in the remote manifest.
225
- fn rb_manifest_languages(ruby: &Ruby) -> Result<Vec<String>, Error> {
226
- tree_sitter_language_pack::manifest_languages()
227
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
228
- }
229
-
230
- /// Get all languages that are already downloaded and cached locally.
231
- fn rb_downloaded_languages() -> Vec<String> {
232
- tree_sitter_language_pack::downloaded_languages()
233
- }
234
-
235
- /// Delete all cached parser shared libraries.
236
- fn rb_clean_cache(ruby: &Ruby) -> Result<(), Error> {
237
- tree_sitter_language_pack::clean_cache().map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
238
- }
239
-
240
- /// Get the effective cache directory path as a string.
241
- fn rb_cache_dir(ruby: &Ruby) -> Result<String, Error> {
242
- tree_sitter_language_pack::cache_dir()
243
- .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))
244
- .and_then(|path| {
245
- path.to_str()
246
- .ok_or_else(|| Error::new(ruby.exception_runtime_error(), "cache path is not valid UTF-8"))
247
- .map(|s| s.to_string())
248
- })
249
- }
250
-
251
- #[magnus::init]
252
- fn init(ruby: &Ruby) -> Result<(), Error> {
253
- let module = ruby.define_module("TreeSitterLanguagePack")?;
254
-
255
- // Registry and parsing functions
256
- module.define_module_function("available_languages", function!(available_languages, 0))?;
257
- module.define_module_function("has_language", function!(has_language, 1))?;
258
- module.define_module_function("detect_language", function!(detect_language, 1))?;
259
- module.define_module_function(
260
- "detect_language_from_content",
261
- function!(detect_language_from_content, 1),
262
- )?;
263
- module.define_module_function(
264
- "detect_language_from_extension",
265
- function!(detect_language_from_extension, 1),
266
- )?;
267
- module.define_module_function("detect_language_from_path", function!(detect_language_from_path, 1))?;
268
- module.define_module_function("extension_ambiguity", function!(extension_ambiguity, 1))?;
269
- module.define_module_function("get_highlights_query", function!(get_highlights_query, 1))?;
270
- module.define_module_function("get_injections_query", function!(get_injections_query, 1))?;
271
- module.define_module_function("get_locals_query", function!(get_locals_query, 1))?;
272
- module.define_module_function("language_count", function!(language_count, 0))?;
273
- module.define_module_function("get_language_ptr", function!(get_language_ptr, 1))?;
274
- module.define_module_function("parse_string", function!(parse_string, 2))?;
275
- module.define_module_function("process", function!(process, 2))?;
276
- module.define_module_function("extract", function!(extract, 2))?;
277
- module.define_module_function("validate_extraction", function!(validate_extraction, 1))?;
278
-
279
- // Download API functions
280
- module.define_module_function("init", function!(rb_init, 1))?;
281
- module.define_module_function("configure", function!(rb_configure, 1))?;
282
- module.define_module_function("download", function!(rb_download, 1))?;
283
- module.define_module_function("download_all", function!(rb_download_all, 0))?;
284
- module.define_module_function("manifest_languages", function!(rb_manifest_languages, 0))?;
285
- module.define_module_function("downloaded_languages", function!(rb_downloaded_languages, 0))?;
286
- module.define_module_function("clean_cache", function!(rb_clean_cache, 0))?;
287
- module.define_module_function("cache_dir", function!(rb_cache_dir, 0))?;
288
-
289
- let tree_class = module.define_class("Tree", ruby.class_object())?;
290
- tree_class.define_method("root_node_type", method!(TreeWrapper::root_node_type, 0))?;
291
- tree_class.define_method("root_child_count", method!(TreeWrapper::root_child_count, 0))?;
292
- tree_class.define_method("contains_node_type", method!(TreeWrapper::contains_node_type, 1))?;
293
- tree_class.define_method("has_error_nodes", method!(TreeWrapper::has_error_nodes, 0))?;
294
-
295
- Ok(())
296
- }