ruby_tree_sitter 0.20.8.2-x86_64-linux → 1.0.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -1
  3. data/README.md +32 -18
  4. data/ext/tree_sitter/extconf.rb +1 -43
  5. data/ext/tree_sitter/input.c +1 -0
  6. data/ext/tree_sitter/language.c +131 -46
  7. data/ext/tree_sitter/logger.c +28 -12
  8. data/ext/tree_sitter/node.c +438 -130
  9. data/ext/tree_sitter/parser.c +232 -37
  10. data/ext/tree_sitter/query.c +197 -72
  11. data/ext/tree_sitter/query_cursor.c +140 -28
  12. data/ext/tree_sitter/repo.rb +121 -0
  13. data/ext/tree_sitter/tree.c +118 -34
  14. data/ext/tree_sitter/tree_cursor.c +205 -33
  15. data/ext/tree_sitter/tree_sitter.c +12 -0
  16. data/lib/tree_sitter/node.rb +43 -9
  17. data/lib/tree_sitter/tree_sitter.so +0 -0
  18. data/lib/tree_sitter/version.rb +4 -2
  19. data/lib/tree_sitter.rb +1 -0
  20. data/lib/tree_stand/ast_modifier.rb +30 -0
  21. data/lib/tree_stand/breadth_first_visitor.rb +54 -0
  22. data/lib/tree_stand/config.rb +13 -0
  23. data/lib/tree_stand/node.rb +224 -0
  24. data/lib/tree_stand/parser.rb +67 -0
  25. data/lib/tree_stand/range.rb +55 -0
  26. data/lib/tree_stand/tree.rb +123 -0
  27. data/lib/tree_stand/utils/printer.rb +73 -0
  28. data/lib/tree_stand/version.rb +7 -0
  29. data/lib/tree_stand/visitor.rb +127 -0
  30. data/lib/tree_stand/visitors/tree_walker.rb +37 -0
  31. data/lib/tree_stand.rb +48 -0
  32. data/tree_sitter.gemspec +15 -12
  33. metadata +37 -107
  34. data/test/README.md +0 -15
  35. data/test/test_helper.rb +0 -9
  36. data/test/tree_sitter/js_test.rb +0 -48
  37. data/test/tree_sitter/language_test.rb +0 -73
  38. data/test/tree_sitter/logger_test.rb +0 -70
  39. data/test/tree_sitter/node_test.rb +0 -355
  40. data/test/tree_sitter/parser_test.rb +0 -140
  41. data/test/tree_sitter/query_test.rb +0 -153
  42. data/test/tree_sitter/tree_cursor_test.rb +0 -83
  43. data/test/tree_sitter/tree_test.rb +0 -51
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../test_helper'
4
-
5
- ruby = TreeSitter.lang('ruby')
6
- parser = TreeSitter::Parser.new
7
- parser.language = ruby
8
-
9
- program = <<~RUBY
10
- def mul(a, b)
11
- res = a * b
12
- puts res.inspect
13
- return res
14
- end
15
- RUBY
16
-
17
- tree = parser.parse_string(nil, program)
18
- root = tree.root_node
19
-
20
- describe 'TreeCursor should work properly' do
21
- before do
22
- @cursor = TreeSitter::TreeCursor.new(root)
23
- end
24
-
25
- it 'must return root node when created' do
26
- assert_equal root, @cursor.current_node
27
- end
28
-
29
- it 'must return root node when reset after creation' do
30
- @cursor.reset(root)
31
- assert_equal root, @cursor.current_node
32
- end
33
-
34
- it 'must reset to an arbitrary node' do
35
- @cursor.reset(root.child(0).child(0))
36
- assert_equal root.child(0).child(0), @cursor.current_node
37
- end
38
-
39
- it 'must move on the tree properly' do
40
- @cursor.goto_first_child
41
- assert_equal root.child(0), @cursor.current_node
42
-
43
- @cursor.goto_first_child
44
- @cursor.goto_next_sibling
45
- assert_equal root.child(0).child(0).next_sibling, @cursor.current_node
46
-
47
- @cursor.goto_parent
48
- assert_equal root.child(0), @cursor.current_node
49
-
50
- @cursor.reset(root)
51
- assert_equal root, @cursor.current_node
52
- end
53
-
54
- it 'must return a String when current_field_name is called on a named child, or nil otherwise' do
55
- assert_nil @cursor.current_field_name
56
-
57
- @cursor.goto_first_child
58
- @cursor.goto_first_child
59
- @cursor.goto_next_sibling
60
-
61
- assert_equal 'name', @cursor.current_field_name
62
- assert_instance_of Integer, @cursor.current_field_id
63
- end
64
-
65
- it 'must return proper child for given byte' do
66
- @cursor.goto_first_child_for_byte(0)
67
- assert_equal root.child(0), @cursor.current_node
68
- end
69
-
70
- it 'must return proper child for given point' do
71
- @cursor.goto_first_child_for_point(root.start_point)
72
- assert_equal root.child(0), @cursor.current_node
73
- end
74
-
75
- it 'must return proper child for given point' do
76
- @cursor.goto_first_child_for_point(root.start_point)
77
- assert_equal root.child(0), @cursor.current_node
78
- end
79
-
80
- it 'must return a distinct copy on copy' do
81
- refute_equal @cursor, @cursor.copy
82
- end
83
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../test_helper.rb'
4
-
5
- ruby = TreeSitter.lang('ruby')
6
- parser = TreeSitter::Parser.new
7
- parser.language = ruby
8
-
9
- program = <<~RUBY
10
- def mul(a, b)
11
- res = a* b
12
- puts res.inspect
13
- return res
14
- end
15
- RUBY
16
-
17
- tree = parser.parse_string(nil, program)
18
-
19
- describe 'copy' do
20
- it 'must make a new copy' do
21
- copy = tree.copy
22
- refute_equal tree, copy
23
- end
24
- end
25
-
26
- describe 'root_node' do
27
- it 'must be of type TreeSitter::Node' do
28
- root = tree.root_node
29
- assert_instance_of TreeSitter::Node, root
30
- end
31
- end
32
-
33
- describe 'language' do
34
- it 'must be identical to parser language' do
35
- assert_equal parser.language, tree.language
36
- end
37
- end
38
-
39
- describe 'print_dot_graph' do
40
- it 'must save to disk' do
41
- dot = File.expand_path('/tmp/tree-dot.gv', FileUtils.getwd)
42
- tree.print_dot_graph(dot)
43
-
44
- assert File.exist?(dot), 'dot file must be exist'
45
- assert File.file?(dot), 'dot file must be a file'
46
- refute_equal 0, File.size(dot)
47
- end
48
- end
49
-
50
- # TODO: edit
51
- # TODO: changed_ranges