yarp 0.6.0 → 0.8.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/CONTRIBUTING.md +4 -0
  4. data/{Makefile.in → Makefile} +5 -4
  5. data/README.md +6 -3
  6. data/config.yml +83 -274
  7. data/docs/build_system.md +4 -15
  8. data/docs/building.md +1 -5
  9. data/docs/encoding.md +1 -0
  10. data/docs/{extension.md → ruby_api.md} +6 -3
  11. data/docs/serialization.md +71 -24
  12. data/ext/yarp/api_node.c +173 -585
  13. data/ext/yarp/extconf.rb +15 -10
  14. data/ext/yarp/extension.c +4 -2
  15. data/ext/yarp/extension.h +1 -1
  16. data/include/yarp/ast.h +167 -306
  17. data/include/yarp/defines.h +5 -15
  18. data/include/yarp/enc/yp_encoding.h +1 -0
  19. data/include/yarp/unescape.h +1 -1
  20. data/include/yarp/util/yp_buffer.h +9 -0
  21. data/include/yarp/util/yp_constant_pool.h +3 -0
  22. data/include/yarp/util/yp_list.h +7 -7
  23. data/include/yarp/util/yp_newline_list.h +4 -0
  24. data/include/yarp/util/yp_state_stack.h +1 -1
  25. data/include/yarp/util/yp_string.h +5 -1
  26. data/include/yarp/version.h +2 -3
  27. data/include/yarp.h +4 -2
  28. data/lib/yarp/ffi.rb +226 -0
  29. data/lib/yarp/lex_compat.rb +16 -2
  30. data/lib/yarp/node.rb +594 -1437
  31. data/lib/yarp/ripper_compat.rb +3 -3
  32. data/lib/yarp/serialize.rb +312 -149
  33. data/lib/yarp.rb +167 -2
  34. data/src/enc/yp_unicode.c +9 -0
  35. data/src/node.c +92 -250
  36. data/src/prettyprint.c +81 -206
  37. data/src/serialize.c +124 -149
  38. data/src/unescape.c +29 -35
  39. data/src/util/yp_buffer.c +18 -0
  40. data/src/util/yp_list.c +7 -16
  41. data/src/util/yp_state_stack.c +0 -6
  42. data/src/util/yp_string.c +8 -17
  43. data/src/yarp.c +444 -717
  44. data/yarp.gemspec +5 -5
  45. metadata +6 -6
  46. data/config.h.in +0 -25
  47. data/configure +0 -4487
data/ext/yarp/extconf.rb CHANGED
@@ -1,13 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mkmf"
4
3
  require "rbconfig"
5
- require "rake"
6
4
 
7
5
  module Yarp
8
6
  module ExtConf
9
7
  class << self
10
8
  def configure
9
+ unless RUBY_ENGINE == "ruby"
10
+ # On non-CRuby we only need the shared library, so build only that and not the C extension.
11
+ # We also avoid `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
12
+ # but we want to use the native toolchain here since librubyparser is run natively.
13
+ build_shared_rubyparser
14
+ File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
15
+ return
16
+ end
17
+
18
+ require "mkmf"
11
19
  configure_c_extension
12
20
  configure_rubyparser
13
21
 
@@ -35,7 +43,7 @@ module Yarp
35
43
  end
36
44
  $LOCAL_LIBS << " #{static_archive_path}"
37
45
  else
38
- shared_library_path = File.join(build_dir, "librubyparser.#{RbConfig::CONFIG["DLEXT"]}")
46
+ shared_library_path = File.join(build_dir, "librubyparser.#{RbConfig::CONFIG["SOEXT"]}")
39
47
  unless File.exist?(shared_library_path)
40
48
  build_shared_rubyparser
41
49
  end
@@ -62,15 +70,12 @@ module Yarp
62
70
 
63
71
  def build_target_rubyparser(target)
64
72
  Dir.chdir(root_dir) do
65
- if !File.exist?("configure") && Dir.exist?(".git")
73
+ if !File.exist?("include/yarp/ast.h") && Dir.exist?(".git")
66
74
  # this block only exists to support building the gem from a "git" source,
67
75
  # normally we package up the configure and other files in the gem itself
68
- Rake.sh("autoconf")
69
- Rake.sh("autoheader")
70
- Rake.sh("templates/template.rb")
76
+ system("templates/template.rb", exception: true)
71
77
  end
72
- Rake.sh("sh", "configure") # explicit "sh" for Windows where shebangs are not supported
73
- Rake.sh("make", target)
78
+ system("make", target, exception: true)
74
79
  end
75
80
  end
76
81
 
@@ -123,7 +128,7 @@ module Yarp
123
128
  end
124
129
  end
125
130
 
126
- if arg_config("--help")
131
+ if ARGV.delete("--help")
127
132
  Yarp::ExtConf.print_help
128
133
  exit!(0)
129
134
  end
data/ext/yarp/extension.c CHANGED
@@ -66,7 +66,7 @@ dump_input(yp_string_t *input, const char *filepath) {
66
66
  yp_node_t *node = yp_parse(&parser);
67
67
  yp_serialize(&parser, node, &buffer);
68
68
 
69
- VALUE result = rb_str_new(buffer.value, buffer.length);
69
+ VALUE result = rb_str_new(yp_buffer_value(&buffer), yp_buffer_length(&buffer));
70
70
  yp_node_destroy(&parser, node);
71
71
  yp_buffer_free(&buffer);
72
72
  yp_parser_free(&parser);
@@ -483,7 +483,7 @@ parse_serialize_file_metadata(VALUE self, VALUE filepath, VALUE metadata) {
483
483
  if (!yp_string_mapped_init(&input, checked)) return Qnil;
484
484
 
485
485
  yp_parse_serialize(yp_string_source(&input), yp_string_length(&input), &buffer, check_string(metadata));
486
- VALUE result = rb_str_new(buffer.value, buffer.length);
486
+ VALUE result = rb_str_new(yp_buffer_value(&buffer), yp_buffer_length(&buffer));
487
487
 
488
488
  yp_buffer_free(&buffer);
489
489
  return result;
@@ -522,6 +522,8 @@ Init_yarp(void) {
522
522
  // in yarp.h.
523
523
  rb_define_const(rb_cYARP, "VERSION", rb_str_new2(EXPECTED_YARP_VERSION));
524
524
 
525
+ rb_define_const(rb_cYARP, "BACKEND", ID2SYM(rb_intern("CExtension")));
526
+
525
527
  // First, the functions that have to do with lexing and parsing.
526
528
  rb_define_singleton_method(rb_cYARP, "dump", dump, -1);
527
529
  rb_define_singleton_method(rb_cYARP, "dump_file", dump_file, 1);
data/ext/yarp/extension.h CHANGED
@@ -5,7 +5,7 @@
5
5
  #include <ruby/encoding.h>
6
6
  #include "yarp.h"
7
7
 
8
- #define EXPECTED_YARP_VERSION "0.6.0"
8
+ #define EXPECTED_YARP_VERSION "0.8.0"
9
9
 
10
10
  VALUE yp_source_new(yp_parser_t *parser);
11
11
  VALUE yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source);