textbringer-tree-sitter 1.0.0

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.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/CLAUDE.md +76 -0
  3. data/LICENSE.txt +13 -0
  4. data/README.md +125 -0
  5. data/Rakefile +12 -0
  6. data/exe/textbringer-tree-sitter +513 -0
  7. data/ext/textbringer_tree_sitter/extconf.rb +125 -0
  8. data/lib/textbringer/tree_sitter/node_maps/bash.rb +57 -0
  9. data/lib/textbringer/tree_sitter/node_maps/c.rb +64 -0
  10. data/lib/textbringer/tree_sitter/node_maps/cobol.rb +94 -0
  11. data/lib/textbringer/tree_sitter/node_maps/csharp.rb +107 -0
  12. data/lib/textbringer/tree_sitter/node_maps/groovy.rb +77 -0
  13. data/lib/textbringer/tree_sitter/node_maps/haml.rb +34 -0
  14. data/lib/textbringer/tree_sitter/node_maps/hcl.rb +53 -0
  15. data/lib/textbringer/tree_sitter/node_maps/html.rb +33 -0
  16. data/lib/textbringer/tree_sitter/node_maps/java.rb +98 -0
  17. data/lib/textbringer/tree_sitter/node_maps/javascript.rb +82 -0
  18. data/lib/textbringer/tree_sitter/node_maps/json.rb +31 -0
  19. data/lib/textbringer/tree_sitter/node_maps/pascal.rb +102 -0
  20. data/lib/textbringer/tree_sitter/node_maps/php.rb +100 -0
  21. data/lib/textbringer/tree_sitter/node_maps/python.rb +72 -0
  22. data/lib/textbringer/tree_sitter/node_maps/ruby.rb +82 -0
  23. data/lib/textbringer/tree_sitter/node_maps/rust.rb +81 -0
  24. data/lib/textbringer/tree_sitter/node_maps/yaml.rb +45 -0
  25. data/lib/textbringer/tree_sitter/node_maps.rb +78 -0
  26. data/lib/textbringer/tree_sitter/version.rb +7 -0
  27. data/lib/textbringer/tree_sitter_adapter.rb +166 -0
  28. data/lib/textbringer/tree_sitter_config.rb +91 -0
  29. data/lib/textbringer_plugin.rb +141 -0
  30. data/parsers/darwin-arm64/.gitkeep +0 -0
  31. data/parsers/darwin-x64/.gitkeep +0 -0
  32. data/parsers/linux-arm64/.gitkeep +0 -0
  33. data/parsers/linux-x64/.gitkeep +0 -0
  34. data/scripts/build_parsers.sh +77 -0
  35. data/scripts/test_parser.rb +223 -0
  36. metadata +139 -0
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ C_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ string_literal
10
+ char_literal
11
+ system_lib_string
12
+ ],
13
+ keyword: %i[
14
+ if
15
+ else
16
+ for
17
+ while
18
+ do
19
+ switch
20
+ case
21
+ default
22
+ break
23
+ continue
24
+ return
25
+ goto
26
+ struct
27
+ union
28
+ enum
29
+ typedef
30
+ sizeof
31
+ static
32
+ extern
33
+ const
34
+ volatile
35
+ inline
36
+ register
37
+ auto
38
+ restrict
39
+ ],
40
+ number: %i[number_literal],
41
+ constant: %i[],
42
+ function_name: %i[function_declarator],
43
+ variable: %i[identifier],
44
+ type: %i[
45
+ primitive_type
46
+ type_identifier
47
+ sized_type_specifier
48
+ ],
49
+ operator: %i[],
50
+ punctuation: %i[],
51
+ builtin: %i[
52
+ true
53
+ false
54
+ null
55
+ ],
56
+ property: %i[field_identifier]
57
+ }.freeze
58
+
59
+ C = C_FEATURES.flat_map { |face, nodes|
60
+ nodes.map { |node| [node, face] }
61
+ }.to_h.freeze
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ # COBOL のノードタイプは大文字が多い
7
+ COBOL_FEATURES = {
8
+ comment: %i[comment],
9
+ string: %i[string_literal],
10
+ keyword: %i[
11
+ PERFORM
12
+ IF
13
+ ELSE
14
+ END
15
+ MOVE
16
+ DISPLAY
17
+ ACCEPT
18
+ ADD
19
+ SUBTRACT
20
+ MULTIPLY
21
+ DIVIDE
22
+ COMPUTE
23
+ EVALUATE
24
+ WHEN
25
+ CALL
26
+ GO
27
+ TO
28
+ STOP
29
+ RUN
30
+ READ
31
+ WRITE
32
+ OPEN
33
+ CLOSE
34
+ SECTION
35
+ DIVISION
36
+ PROGRAM
37
+ DATA
38
+ WORKING
39
+ STORAGE
40
+ FILE
41
+ PROCEDURE
42
+ IDENTIFICATION
43
+ ENVIRONMENT
44
+ CONFIGURATION
45
+ INPUT
46
+ OUTPUT
47
+ SELECT
48
+ ASSIGN
49
+ ORGANIZATION
50
+ ACCESS
51
+ RECORD
52
+ PIC
53
+ PICTURE
54
+ VALUE
55
+ OCCURS
56
+ TIMES
57
+ THRU
58
+ THROUGH
59
+ VARYING
60
+ FROM
61
+ BY
62
+ UNTIL
63
+ WITH
64
+ TEST
65
+ BEFORE
66
+ AFTER
67
+ RETURNING
68
+ GIVING
69
+ USING
70
+ NOT
71
+ AND
72
+ OR
73
+ GREATER
74
+ LESS
75
+ EQUAL
76
+ THAN
77
+ ],
78
+ number: %i[number],
79
+ constant: %i[],
80
+ function_name: %i[],
81
+ variable: %i[identifier],
82
+ type: %i[],
83
+ operator: %i[],
84
+ punctuation: %i[],
85
+ builtin: %i[ZERO ZEROS ZEROES SPACE SPACES LOW-VALUE HIGH-VALUE],
86
+ property: %i[]
87
+ }.freeze
88
+
89
+ COBOL = COBOL_FEATURES.flat_map { |face, nodes|
90
+ nodes.map { |node| [node, face] }
91
+ }.to_h.freeze
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ CSHARP_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ string_literal
10
+ verbatim_string_literal
11
+ interpolated_string_expression
12
+ character_literal
13
+ ],
14
+ keyword: %i[
15
+ if
16
+ else
17
+ for
18
+ foreach
19
+ while
20
+ do
21
+ switch
22
+ case
23
+ default
24
+ break
25
+ continue
26
+ return
27
+ goto
28
+ throw
29
+ try
30
+ catch
31
+ finally
32
+ class
33
+ struct
34
+ interface
35
+ enum
36
+ namespace
37
+ using
38
+ public
39
+ private
40
+ protected
41
+ internal
42
+ static
43
+ readonly
44
+ const
45
+ volatile
46
+ virtual
47
+ override
48
+ abstract
49
+ sealed
50
+ new
51
+ this
52
+ base
53
+ void
54
+ var
55
+ async
56
+ await
57
+ yield
58
+ in
59
+ out
60
+ ref
61
+ params
62
+ where
63
+ get
64
+ set
65
+ add
66
+ remove
67
+ partial
68
+ extern
69
+ unsafe
70
+ fixed
71
+ lock
72
+ checked
73
+ unchecked
74
+ stackalloc
75
+ sizeof
76
+ typeof
77
+ nameof
78
+ is
79
+ as
80
+ null
81
+ true
82
+ false
83
+ ],
84
+ number: %i[
85
+ integer_literal
86
+ real_literal
87
+ ],
88
+ constant: %i[],
89
+ function_name: %i[],
90
+ variable: %i[identifier],
91
+ type: %i[
92
+ predefined_type
93
+ type_identifier
94
+ generic_name
95
+ ],
96
+ operator: %i[],
97
+ punctuation: %i[],
98
+ builtin: %i[],
99
+ property: %i[]
100
+ }.freeze
101
+
102
+ CSHARP = CSHARP_FEATURES.flat_map { |face, nodes|
103
+ nodes.map { |node| [node, face] }
104
+ }.to_h.freeze
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ GROOVY_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ string
10
+ gstring
11
+ string_content
12
+ ],
13
+ keyword: %i[
14
+ if
15
+ else
16
+ for
17
+ while
18
+ do
19
+ switch
20
+ case
21
+ default
22
+ break
23
+ continue
24
+ return
25
+ throw
26
+ try
27
+ catch
28
+ finally
29
+ class
30
+ interface
31
+ enum
32
+ trait
33
+ extends
34
+ implements
35
+ import
36
+ package
37
+ def
38
+ var
39
+ public
40
+ private
41
+ protected
42
+ static
43
+ final
44
+ abstract
45
+ synchronized
46
+ native
47
+ transient
48
+ volatile
49
+ new
50
+ this
51
+ super
52
+ instanceof
53
+ in
54
+ as
55
+ assert
56
+ ],
57
+ number: %i[number_literal],
58
+ constant: %i[],
59
+ function_name: %i[],
60
+ variable: %i[identifier],
61
+ type: %i[type_identifier],
62
+ operator: %i[],
63
+ punctuation: %i[],
64
+ builtin: %i[
65
+ true
66
+ false
67
+ null
68
+ ],
69
+ property: %i[]
70
+ }.freeze
71
+
72
+ GROOVY = GROOVY_FEATURES.flat_map { |face, nodes|
73
+ nodes.map { |node| [node, face] }
74
+ }.to_h.freeze
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ HAML_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ string
10
+ string_content
11
+ ],
12
+ keyword: %i[doctype],
13
+ number: %i[],
14
+ constant: %i[],
15
+ function_name: %i[],
16
+ variable: %i[],
17
+ type: %i[],
18
+ operator: %i[],
19
+ punctuation: %i[],
20
+ builtin: %i[],
21
+ property: %i[
22
+ tag_name
23
+ id
24
+ class
25
+ attribute_name
26
+ ]
27
+ }.freeze
28
+
29
+ HAML = HAML_FEATURES.flat_map { |face, nodes|
30
+ nodes.map { |node| [node, face] }
31
+ }.to_h.freeze
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ # HCL (HashiCorp Configuration Language) Feature-based ノードマッピング
7
+ # Rouge の Terraform lexer では認識されない for, in, function_call を正しく処理
8
+ HCL_FEATURES = {
9
+ comment: %i[comment],
10
+ string: %i[
11
+ string_lit
12
+ quoted_template
13
+ heredoc_template
14
+ template_literal
15
+ ],
16
+ keyword: %i[
17
+ for
18
+ in
19
+ if
20
+ else
21
+ endif
22
+ endfor
23
+ true
24
+ false
25
+ null
26
+ ],
27
+ number: %i[numeric_lit],
28
+ constant: %i[],
29
+ function_name: %i[function_call],
30
+ variable: %i[
31
+ identifier
32
+ variable_expr
33
+ ],
34
+ type: %i[],
35
+ operator: %i[
36
+ binary_operation
37
+ unary_operation
38
+ ],
39
+ punctuation: %i[],
40
+ builtin: %i[],
41
+ property: %i[
42
+ attribute
43
+ block
44
+ ]
45
+ }.freeze
46
+
47
+ # Feature → Face の展開
48
+ HCL = HCL_FEATURES.flat_map { |face, nodes|
49
+ nodes.map { |node| [node, face] }
50
+ }.to_h.freeze
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ HTML_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ attribute_value
10
+ quoted_attribute_value
11
+ ],
12
+ keyword: %i[doctype],
13
+ number: %i[],
14
+ constant: %i[],
15
+ function_name: %i[],
16
+ variable: %i[],
17
+ type: %i[],
18
+ operator: %i[],
19
+ punctuation: %i[],
20
+ builtin: %i[],
21
+ property: %i[
22
+ tag_name
23
+ attribute_name
24
+ erroneous_end_tag_name
25
+ ]
26
+ }.freeze
27
+
28
+ HTML = HTML_FEATURES.flat_map { |face, nodes|
29
+ nodes.map { |node| [node, face] }
30
+ }.to_h.freeze
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ JAVA_FEATURES = {
7
+ comment: %i[
8
+ comment
9
+ line_comment
10
+ block_comment
11
+ ],
12
+ string: %i[
13
+ string_literal
14
+ character_literal
15
+ text_block
16
+ ],
17
+ keyword: %i[
18
+ if
19
+ else
20
+ for
21
+ while
22
+ do
23
+ switch
24
+ case
25
+ default
26
+ break
27
+ continue
28
+ return
29
+ throw
30
+ try
31
+ catch
32
+ finally
33
+ class
34
+ interface
35
+ enum
36
+ record
37
+ extends
38
+ implements
39
+ import
40
+ package
41
+ public
42
+ private
43
+ protected
44
+ static
45
+ final
46
+ abstract
47
+ synchronized
48
+ native
49
+ transient
50
+ volatile
51
+ strictfp
52
+ new
53
+ this
54
+ super
55
+ instanceof
56
+ void
57
+ assert
58
+ throws
59
+ permits
60
+ sealed
61
+ non
62
+ var
63
+ yield
64
+ ],
65
+ number: %i[
66
+ decimal_integer_literal
67
+ hex_integer_literal
68
+ octal_integer_literal
69
+ binary_integer_literal
70
+ decimal_floating_point_literal
71
+ hex_floating_point_literal
72
+ ],
73
+ constant: %i[],
74
+ function_name: %i[],
75
+ variable: %i[identifier],
76
+ type: %i[
77
+ type_identifier
78
+ void_type
79
+ integral_type
80
+ floating_point_type
81
+ boolean_type
82
+ ],
83
+ operator: %i[],
84
+ punctuation: %i[],
85
+ builtin: %i[
86
+ true
87
+ false
88
+ null
89
+ ],
90
+ property: %i[]
91
+ }.freeze
92
+
93
+ JAVA = JAVA_FEATURES.flat_map { |face, nodes|
94
+ nodes.map { |node| [node, face] }
95
+ }.to_h.freeze
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ JAVASCRIPT_FEATURES = {
7
+ comment: %i[comment],
8
+ string: %i[
9
+ string
10
+ template_string
11
+ regex
12
+ ],
13
+ keyword: %i[
14
+ if
15
+ else
16
+ for
17
+ while
18
+ do
19
+ switch
20
+ case
21
+ default
22
+ break
23
+ continue
24
+ return
25
+ throw
26
+ try
27
+ catch
28
+ finally
29
+ function
30
+ class
31
+ extends
32
+ new
33
+ this
34
+ super
35
+ import
36
+ export
37
+ from
38
+ as
39
+ const
40
+ let
41
+ var
42
+ in
43
+ of
44
+ instanceof
45
+ typeof
46
+ void
47
+ delete
48
+ async
49
+ await
50
+ yield
51
+ static
52
+ get
53
+ set
54
+ debugger
55
+ with
56
+ ],
57
+ number: %i[number],
58
+ constant: %i[],
59
+ function_name: %i[],
60
+ variable: %i[
61
+ identifier
62
+ property_identifier
63
+ shorthand_property_identifier
64
+ ],
65
+ type: %i[],
66
+ operator: %i[],
67
+ punctuation: %i[],
68
+ builtin: %i[
69
+ true
70
+ false
71
+ null
72
+ undefined
73
+ ],
74
+ property: %i[]
75
+ }.freeze
76
+
77
+ JAVASCRIPT = JAVASCRIPT_FEATURES.flat_map { |face, nodes|
78
+ nodes.map { |node| [node, face] }
79
+ }.to_h.freeze
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module TreeSitter
5
+ module NodeMaps
6
+ # JSON_LANG - Ruby の JSON モジュールと名前衝突を避けるため
7
+ JSON_FEATURES = {
8
+ comment: %i[],
9
+ string: %i[string],
10
+ keyword: %i[],
11
+ number: %i[number],
12
+ constant: %i[],
13
+ function_name: %i[],
14
+ variable: %i[],
15
+ type: %i[],
16
+ operator: %i[],
17
+ punctuation: %i[],
18
+ builtin: %i[
19
+ true
20
+ false
21
+ null
22
+ ],
23
+ property: %i[pair]
24
+ }.freeze
25
+
26
+ JSON_LANG = JSON_FEATURES.flat_map { |face, nodes|
27
+ nodes.map { |node| [node, face] }
28
+ }.to_h.freeze
29
+ end
30
+ end
31
+ end