kanayago 0.1.1 → 0.3.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -0
  3. data/.ruby-version +1 -0
  4. data/README.md +20 -29
  5. data/Rakefile +24 -120
  6. data/ext/kanayago/extconf.rb +14 -0
  7. data/ext/kanayago/kanayago.c +554 -235
  8. data/ext/kanayago/kanayago.h +5 -0
  9. data/ext/kanayago/literal_node.c +343 -0
  10. data/ext/kanayago/literal_node.h +30 -0
  11. data/ext/kanayago/pattern_node.c +78 -0
  12. data/ext/kanayago/pattern_node.h +13 -0
  13. data/ext/kanayago/scope_node.c +34 -0
  14. data/ext/kanayago/scope_node.h +8 -0
  15. data/ext/kanayago/statement_node.c +795 -0
  16. data/ext/kanayago/statement_node.h +66 -0
  17. data/ext/kanayago/string_node.c +192 -0
  18. data/ext/kanayago/string_node.h +19 -0
  19. data/ext/kanayago/variable_node.c +72 -0
  20. data/ext/kanayago/variable_node.h +12 -0
  21. data/lib/kanayago/literal_node.rb +87 -0
  22. data/lib/kanayago/pattern_node.rb +19 -0
  23. data/lib/kanayago/statement_node.rb +222 -0
  24. data/lib/kanayago/string_node.rb +43 -0
  25. data/lib/kanayago/variable_node.rb +23 -0
  26. data/lib/kanayago/version.rb +1 -1
  27. data/lib/kanayago.rb +22 -0
  28. data/patch/3.4/copy_target.rb +78 -0
  29. data/patch/3.4/kanayago.patch +162 -0
  30. data/patch/head/copy_target.rb +84 -0
  31. data/patch/head/kanayago.patch +162 -0
  32. data/sample/minitest_generator.rb +266 -0
  33. data/sample/test_generator.rb +272 -0
  34. data/script/setup_parser.rb +136 -0
  35. data/typeprof.conf.json +9 -0
  36. metadata +30 -64
  37. data/ext/kanayago/ccan/check_type/check_type.h +0 -63
  38. data/ext/kanayago/ccan/container_of/container_of.h +0 -142
  39. data/ext/kanayago/ccan/list/list.h +0 -791
  40. data/ext/kanayago/ccan/str/str.h +0 -17
  41. data/ext/kanayago/constant.h +0 -53
  42. data/ext/kanayago/id.h +0 -347
  43. data/ext/kanayago/id_table.h +0 -39
  44. data/ext/kanayago/internal/array.h +0 -151
  45. data/ext/kanayago/internal/basic_operators.h +0 -64
  46. data/ext/kanayago/internal/bignum.h +0 -244
  47. data/ext/kanayago/internal/bits.h +0 -568
  48. data/ext/kanayago/internal/compile.h +0 -34
  49. data/ext/kanayago/internal/compilers.h +0 -107
  50. data/ext/kanayago/internal/complex.h +0 -29
  51. data/ext/kanayago/internal/encoding.h +0 -36
  52. data/ext/kanayago/internal/error.h +0 -218
  53. data/ext/kanayago/internal/fixnum.h +0 -184
  54. data/ext/kanayago/internal/gc.h +0 -322
  55. data/ext/kanayago/internal/hash.h +0 -191
  56. data/ext/kanayago/internal/imemo.h +0 -261
  57. data/ext/kanayago/internal/io.h +0 -140
  58. data/ext/kanayago/internal/numeric.h +0 -274
  59. data/ext/kanayago/internal/parse.h +0 -117
  60. data/ext/kanayago/internal/rational.h +0 -71
  61. data/ext/kanayago/internal/re.h +0 -28
  62. data/ext/kanayago/internal/ruby_parser.h +0 -125
  63. data/ext/kanayago/internal/sanitizers.h +0 -297
  64. data/ext/kanayago/internal/serial.h +0 -23
  65. data/ext/kanayago/internal/static_assert.h +0 -16
  66. data/ext/kanayago/internal/string.h +0 -186
  67. data/ext/kanayago/internal/symbol.h +0 -45
  68. data/ext/kanayago/internal/thread.h +0 -79
  69. data/ext/kanayago/internal/variable.h +0 -72
  70. data/ext/kanayago/internal/vm.h +0 -137
  71. data/ext/kanayago/internal/warnings.h +0 -16
  72. data/ext/kanayago/internal.h +0 -108
  73. data/ext/kanayago/lex.c +0 -302
  74. data/ext/kanayago/method.h +0 -255
  75. data/ext/kanayago/node.c +0 -440
  76. data/ext/kanayago/node.h +0 -111
  77. data/ext/kanayago/node_name.inc +0 -224
  78. data/ext/kanayago/parse.c +0 -26931
  79. data/ext/kanayago/parse.h +0 -244
  80. data/ext/kanayago/parse.tmp.y +0 -16145
  81. data/ext/kanayago/parser_bits.h +0 -564
  82. data/ext/kanayago/parser_node.h +0 -32
  83. data/ext/kanayago/parser_st.c +0 -164
  84. data/ext/kanayago/parser_st.h +0 -162
  85. data/ext/kanayago/parser_value.h +0 -106
  86. data/ext/kanayago/probes.h +0 -4
  87. data/ext/kanayago/ruby_assert.h +0 -14
  88. data/ext/kanayago/ruby_atomic.h +0 -23
  89. data/ext/kanayago/ruby_parser.c +0 -1165
  90. data/ext/kanayago/rubyparser.h +0 -1391
  91. data/ext/kanayago/shape.h +0 -234
  92. data/ext/kanayago/st.c +0 -2339
  93. data/ext/kanayago/symbol.h +0 -123
  94. data/ext/kanayago/thread_pthread.h +0 -168
  95. data/ext/kanayago/universal_parser.c +0 -230
  96. data/ext/kanayago/vm_core.h +0 -2215
  97. data/ext/kanayago/vm_opts.h +0 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dc8924bd1972c79a19ec99a5317d3805ec71536f4f53e11ee12e11930c16af2
4
- data.tar.gz: a7ef01c1049b9e4132299b21a58b37ecd61fd18813f5f9208a02f6950d3b46fa
3
+ metadata.gz: 5a3eb2ad59c4bf7537be2abff7da6f0b93e79173d8fa6ae51dee86a8966ee83b
4
+ data.tar.gz: c2c4608ccf7ef25054abd327702f6fbd1713c31769bb78062290d8248bce9b0f
5
5
  SHA512:
6
- metadata.gz: 29da7596273da188566563726bd3cd26fde141ec06c30cad03ddc0b52ccc7083815c125425d011a14e253fc070fecf71831d56523064f8fbfbc9bca3fc3d7da2
7
- data.tar.gz: 03c77678bee8697c788a9ef5d7f9e65db5014608ba41f0d9e2223f1b1cfd96195aa8379d05482a404deeaa9d9b17dd72c3f015cf889b9f74b8e29255e356e8d1
6
+ metadata.gz: 16dd25fc0a69b15b85010abd4bb4784d2559cd7a5a0024bd4b60814fa2b376249d222a1c16cd16c049db31cbe855fb12eb5571e3af872e9d83d36a08e9fdd6f8
7
+ data.tar.gz: 07b9d5a878182eedb53d637dd6f4a02d8b53fdd8b0f7a6786ce045d3269abc52843c9792efcd9f482d1f7ebf4e7fa7e051548b998f48f81703799b975bf85fd1
data/.rubocop.yml CHANGED
@@ -1,13 +1,25 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ NewCops: enable
5
+
3
6
  Metrics/BlockLength:
4
7
  Exclude:
5
8
  - Rakefile
6
9
  - kanayago.gemspec
7
10
 
11
+ Metrics/AbcSize:
12
+ Enabled: false
13
+
14
+ Minitest/MultipleAssertions:
15
+ Enabled: false
16
+
8
17
  RBS:
9
18
  Enabled: true
10
19
 
20
+ Style/Documentation:
21
+ Enabled: false
22
+
11
23
  require:
12
24
  - rubocop-minitest
13
25
  - rubocop-on-rbs
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-dev
data/README.md CHANGED
@@ -1,16 +1,21 @@
1
- # Kanayago
1
+ # Kanayago(金屋子)
2
2
 
3
3
  Trying to Make Ruby's Parser Available as a Gem.
4
4
 
5
- ## Installation
5
+ ## Support Ruby version
6
6
 
7
- First, install Ruby master with Universal Parser.
7
+ Kanayago(金屋子) is supported Ruby 3.4 or Ruby head.
8
+
9
+ ## Installation
10
+ ### From RubyGems
8
11
 
9
- ```console
10
- RUBY_CONFIGURE_OPTS="cppflags=-DUNIVERSAL_PARSER" rbenv install ruby-dev
11
12
  ```
13
+ gem install kanayago
14
+ ```
15
+
16
+ ### Build and Install in local
12
17
 
13
- Clone this repository.
18
+ First, clone this repository.
14
19
 
15
20
  ```console
16
21
  git clone https://github.com/S-H-GAMELINKS/kanayago.git
@@ -26,7 +31,7 @@ Finally, build `Kanayago` gem and install it.
26
31
 
27
32
  ```console
28
33
  bundle exec rake build
29
- gem install pkg/kanayago-0.1.0.gem
34
+ gem install pkg/kanayago-0.3.0.gem
30
35
  ```
31
36
 
32
37
  ## Usage
@@ -35,29 +40,15 @@ gem install pkg/kanayago-0.1.0.gem
35
40
  require 'kanayago/kanayago'
36
41
 
37
42
  result = Kanayago.parse('117 + 117')
43
+ # => #<Kanayago::ScopeNode:0x00007f522199c5a8>
44
+
45
+ p result.body
46
+ # => #<Kanayago::OperatorCallNode:0x00007f5221b06358>
38
47
 
39
- p result
40
- # =>
41
- #{
42
- # "NODE_SCOPE" => {
43
- # "args" => nil,
44
- # "body" => {
45
- # "NODE_OPCALL" => {
46
- # "recv" => {
47
- # "NODE_INTEGER" => 117
48
- # },
49
- # "mid" => :+,
50
- # "args" => {
51
- # "NODE_LIST" => [
52
- # {
53
- # "NODE_INTEGER"=>117
54
- # }
55
- # ]
56
- # }
57
- # }
58
- # }
59
- # }
60
- #}
48
+ p result.body.recv
49
+ p result.body.recv.val
50
+ # => #<Kanayago::IntegerNode:0x00007f5221b06330>
51
+ # => 117
61
52
  ```
62
53
 
63
54
  ## Development
data/Rakefile CHANGED
@@ -7,129 +7,23 @@ require 'test_queue'
7
7
  require 'test_queue/runner/minitest'
8
8
  require 'fileutils'
9
9
 
10
- COPY_TARGETS = %w[
11
- ccan/check_type/check_type.h
12
- ccan/container_of/container_of.h
13
- ccan/list/list.h
14
- ccan/str/str.h
15
- constant.h
16
- id_table.h
17
- internal/array.h
18
- internal/basic_operators.h
19
- internal/bignum.h
20
- internal/bits.h
21
- internal/compile.h
22
- internal/compilers.h
23
- internal/complex.h
24
- internal/encoding.h
25
- internal/error.h
26
- internal/fixnum.h
27
- internal/gc.h
28
- internal/hash.h
29
- internal/imemo.h
30
- internal/io.h
31
- internal/numeric.h
32
- internal/parse.h
33
- internal/rational.h
34
- internal/re.h
35
- internal/ruby_parser.h
36
- internal/sanitizers.h
37
- internal/serial.h
38
- internal/static_assert.h
39
- internal/string.h
40
- internal/symbol.h
41
- internal/thread.h
42
- internal/variable.h
43
- internal/warnings.h
44
- internal/vm.h
45
- internal.h
46
- method.h
47
- node.c
48
- node.h
49
- parse.y
50
- parser_bits.h
51
- parser_node.h
52
- parser_st.c
53
- parser_st.h
54
- parser_value.h
55
- ruby_assert.h
56
- ruby_atomic.h
57
- ruby_parser.c
58
- rubyparser.h
59
- shape.h
60
- st.c
61
- symbol.h
62
- thread_pthread.h
63
- universal_parser.c
64
- vm_core.h
65
- vm_opts.h
66
- ].freeze
10
+ if RUBY_DESCRIPTION.include?('dev')
11
+ require_relative 'patch/head/copy_target'
12
+ else
13
+ require_relative "patch/#{RUBY_VERSION[0..2]}/copy_target"
14
+ end
67
15
 
68
16
  namespace :ruby_parser do
69
- desc 'import ruby parser files'
70
- task :import do
71
- `git clone https://github.com/ruby/ruby.git tmp/ruby --depth=1`
72
-
73
- dist = File.expand_path('ext/kanayago', __dir__)
74
- ruby_dir = File.expand_path('tmp/ruby', __dir__)
75
-
76
- directories = ['ccan', 'ccan/check_type', 'ccan/container', 'ccan/container_of', 'ccan/list', 'ccan/str',
77
- 'internal']
78
-
79
- directories.each do |dir|
80
- Dir.mkdir File.join(dist, dir)
81
- end
82
-
83
- COPY_TARGETS.each do |target|
84
- FileUtils.cp File.join(ruby_dir, target), File.join(dist, target)
85
- end
86
-
87
- # "parse.tmp.y"
88
- id2token_path = File.join(ruby_dir, 'tool/id2token.rb')
89
- parse_y_path = File.join(dist, 'parse.y')
90
- parse_tmp_y_path = File.join(dist, 'parse.tmp.y')
91
- sh "ruby #{id2token_path} #{parse_y_path} > #{parse_tmp_y_path}"
92
-
93
- # "id.h"
94
- generic_erb_path = File.join(ruby_dir, 'tool/generic_erb.rb')
95
- id_h_tmpl_path = File.join(ruby_dir, 'template/id.h.tmpl')
96
- id_h_path = File.join(dist, 'id.h')
97
- sh "ruby #{generic_erb_path} --output=#{id_h_path} #{id_h_tmpl_path}"
98
-
99
- # "probes.h"
100
- probes_h_path = File.join(dist, 'probes.h')
101
- File.open(probes_h_path, 'w+') do |f|
102
- f << <<~SRC
103
- #define RUBY_DTRACE_PARSE_BEGIN_ENABLED() (0)
104
- #define RUBY_DTRACE_PARSE_BEGIN(arg0, arg1) (void)(arg0), (void)(arg1);
105
- #define RUBY_DTRACE_PARSE_END_ENABLED() (0)
106
- #define RUBY_DTRACE_PARSE_END(arg0, arg1) (void)(arg0), (void)(arg1);
107
- SRC
108
- end
109
-
110
- # "node_name.inc"
111
- node_name_path = File.join(ruby_dir, 'tool/node_name.rb')
112
- rubyparser_h_path = File.join(dist, 'rubyparser.h')
113
- node_name_inc_path = File.join(dist, 'node_name.inc')
114
- sh "ruby -n #{node_name_path} < #{rubyparser_h_path} > #{node_name_inc_path}"
115
-
116
- # "lex.c"
117
- sh 'cd tmp/ruby && ./autogen.sh && ./configure && make'
118
- FileUtils.mv File.join(ruby_dir, 'lex.c'), File.join(dist, 'lex.c')
119
-
120
- `rm -rf tmp/ruby`
121
- end
122
-
123
- desc 'build ruby parse.c and parse.h with lrama'
124
- task :build do
125
- sh 'bundle exec lrama -oext/kanayago/parse.c -Hext/kanayago/parse.h ext/kanayago/parse.tmp.y'
17
+ desc 'import ruby parser files and apply patch'
18
+ task :setup do
19
+ sh 'ruby script/setup_parser.rb'
126
20
  end
127
21
 
128
22
  desc 'clean to ruby parser file'
129
23
  task :clean do
130
24
  dist = File.expand_path('./ext/kanayago')
131
25
 
132
- COPY_TARGETS.each do |target|
26
+ RUBY_PARSER_COPY_TARGETS.each do |target|
133
27
  FileUtils.rm File.join(dist, target), force: true
134
28
  end
135
29
  delete_files = ['constant.h', 'id.h', 'id.h', 'id.h', 'id_table.h', 'lex.c', 'node_name.inc', 'parse.c', 'parse.h',
@@ -139,16 +33,14 @@ namespace :ruby_parser do
139
33
  FileUtils.rm File.join(dist, file), force: true
140
34
  end
141
35
 
142
- delete_directories = %w[ccan internal]
143
-
144
- delete_directories.each do |dir|
36
+ DELETE_DIRECTORIES.each do |dir|
145
37
  FileUtils.rm_rf File.join(dist, dir)
146
38
  end
147
39
  end
148
40
  end
149
41
 
150
- task build: ['ruby_parser:build', 'compile']
151
- task install: ['ruby_parser:build', 'compile']
42
+ task :build # rubocop:disable Rake/Desc
43
+ task install: ['ruby_parser:clean', 'ruby_parser:setup', 'compile']
152
44
 
153
45
  GEMSPEC = Gem::Specification.load('kanayago.gemspec')
154
46
 
@@ -169,6 +61,18 @@ Rake::TestTask.new(:test) do |t|
169
61
  t.test_files = FileList['test/**/*_test.rb']
170
62
  end
171
63
 
64
+ namespace :sample do
65
+ desc 'Generate RSpec tests from Ruby code using Kanayago AST'
66
+ task :rspec_generate do
67
+ sh 'ruby sample/test_generator.rb'
68
+ end
69
+
70
+ desc 'Generate Minitest tests from Ruby code using Kanayago AST'
71
+ task :minitest_generate do
72
+ sh 'ruby sample/minitest_generator.rb'
73
+ end
74
+ end
75
+
172
76
  desc 'try to kanayago code'
173
77
  task :run do
174
78
  sh 'ruby test.rb'
@@ -2,12 +2,26 @@
2
2
 
3
3
  require 'mkmf'
4
4
 
5
+ # Run setup script to prepare Ruby parser files before building
6
+ setup_script = File.expand_path('../../script/setup_parser.rb', __dir__)
7
+ puts 'Running parser setup script...'
8
+ unless system("ruby #{setup_script}")
9
+ warn 'Failed to setup parser files. Please check the error messages above.'
10
+ exit 1
11
+ end
12
+
5
13
  $objs = %w[
6
14
  node
7
15
  parse
8
16
  parser_st
9
17
  ruby_parser
10
18
  kanayago
19
+ scope_node
20
+ literal_node
21
+ string_node
22
+ statement_node
23
+ variable_node
24
+ pattern_node
11
25
  ].map do |o|
12
26
  o + ".#{$OBJEXT}"
13
27
  end