prism 2.0.0.rc1-x86_64-linux-gnu → 2.0.0-x86_64-linux-gnu

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/CODE_OF_CONDUCT.md +1 -1
  4. data/LICENSE.md +1 -1
  5. data/docs/serialization.md +20 -6
  6. data/ext/prism/api_node.c +81 -81
  7. data/ext/prism/extension.c +54 -69
  8. data/ext/prism/extension.h +1 -1
  9. data/include/prism/arena.h +8 -0
  10. data/include/prism/arena.hpp +42 -0
  11. data/include/prism/ast.h +11 -1
  12. data/include/prism/ast.hpp +641 -0
  13. data/include/prism/buffer.h +8 -0
  14. data/include/prism/buffer.hpp +55 -0
  15. data/include/prism/comments.h +17 -0
  16. data/include/prism/compiler/accel.h +3 -1
  17. data/include/prism/compiler/branch.h +26 -0
  18. data/include/prism/compiler/bswap.h +46 -0
  19. data/include/prism/compiler/cplusplus.hpp +16 -0
  20. data/include/prism/compiler/endianness.h +34 -0
  21. data/include/prism/compiler/exceptions.hpp +17 -0
  22. data/include/prism/compiler/format.h +2 -0
  23. data/include/prism/compiler/lifetimebound.hpp +25 -0
  24. data/include/prism/constant_pool.h +25 -0
  25. data/include/prism/diagnostic.h +18 -0
  26. data/include/prism/errors_format.h +8 -0
  27. data/include/prism/internal/buffer.h +3 -0
  28. data/include/prism/internal/node.h +8 -4
  29. data/include/prism/internal/parser.h +20 -0
  30. data/include/prism/internal/stringy.h +1 -6
  31. data/include/prism/internal/xxh3.h +16 -0
  32. data/include/prism/json.h +8 -0
  33. data/include/prism/line_offset_list.h +8 -0
  34. data/include/prism/magic_comments.h +18 -0
  35. data/include/prism/node.h +55 -10
  36. data/include/prism/node.hpp +272 -0
  37. data/include/prism/node_type.hpp +38 -0
  38. data/include/prism/options.h +10 -1
  39. data/include/prism/options.hpp +43 -0
  40. data/include/prism/parser.h +93 -64
  41. data/include/prism/parser.hpp +274 -0
  42. data/include/prism/prettyprint.h +8 -0
  43. data/include/prism/serialize.h +8 -0
  44. data/include/prism/source.h +8 -0
  45. data/include/prism/stream.h +8 -0
  46. data/include/prism/string_query.h +19 -0
  47. data/include/prism/stringy.h +16 -27
  48. data/include/prism/stringy.hpp +31 -0
  49. data/include/prism/version.h +9 -1
  50. data/include/prism.h +0 -8
  51. data/include/prism.hpp +24 -0
  52. data/lib/prism/3.3/prism.so +0 -0
  53. data/lib/prism/3.4/prism.so +0 -0
  54. data/lib/prism/4.0/prism.so +0 -0
  55. data/lib/prism/ffi.rb +6 -0
  56. data/lib/prism/node.rb +736 -0
  57. data/lib/prism/parse_result.rb +23 -8
  58. data/lib/prism/serialize.rb +2567 -3286
  59. data/lib/prism/string_query.rb +8 -0
  60. data/prism.gemspec +21 -4
  61. data/rbi/generated/prism/node.rbi +2430 -968
  62. data/rbi/generated/prism/parse_result.rbi +16 -4
  63. data/rbi/generated/prism/serialize.rbi +8 -4
  64. data/rbi/generated/prism/string_query.rbi +7 -0
  65. data/sig/generated/prism/node.rbs +2439 -967
  66. data/sig/generated/prism/parse_result.rbs +16 -4
  67. data/sig/generated/prism/serialize.rbs +9 -4
  68. data/sig/generated/prism/string_query.rbs +7 -0
  69. data/src/buffer.c +9 -0
  70. data/src/comments.c +2 -2
  71. data/src/diagnostic.c +8 -0
  72. data/src/node.c +216 -368
  73. data/src/options.c +7 -13
  74. data/src/parser.c +70 -48
  75. data/src/prism.c +581 -419
  76. data/src/regexp.c +0 -1
  77. data/src/serialize.c +2301 -1950
  78. data/src/source.c +8 -2
  79. data/src/string_query.c +14 -0
  80. data/src/stringy.c +3 -33
  81. data/src/xxh3.c +292 -0
  82. metadata +20 -3
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file stringy.h
3
3
  *
4
- * A generic string type that can have various ownership semantics.
4
+ * A view of a sequence of bytes owned by someone else.
5
5
  */
6
6
  #ifndef PRISM_STRINGY_H
7
7
  #define PRISM_STRINGY_H
@@ -12,8 +12,13 @@
12
12
  #include <stddef.h>
13
13
  #include <stdint.h>
14
14
 
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
15
19
  /**
16
- * A generic string type that can have various ownership semantics.
20
+ * A view of a sequence of bytes. The string does not own the bytes, so they
21
+ * must remain valid for as long as the string is in use.
17
22
  */
18
23
  typedef struct {
19
24
  /** A pointer to the start of the string. */
@@ -21,37 +26,17 @@ typedef struct {
21
26
 
22
27
  /** The length of the string in bytes of memory. */
23
28
  size_t length;
24
-
25
- /** The type of the string. This field determines how the string should be freed. */
26
- enum {
27
- /** This string is a constant string, and should not be freed. */
28
- PM_STRING_CONSTANT,
29
-
30
- /** This is a slice of another string, and should not be freed. */
31
- PM_STRING_SHARED,
32
-
33
- /** This string owns its memory, and should be freed internally. */
34
- PM_STRING_OWNED
35
- } type;
36
29
  } pm_string_t;
37
30
 
38
31
  /**
39
- * Initialize a constant string that doesn't own its memory source.
40
- *
41
- * @param string The string to initialize.
42
- * @param source The source of the string.
43
- * @param length The length of the string.
44
- */
45
- PRISM_EXPORTED_FUNCTION void pm_string_constant_init(pm_string_t *string, const char *source, size_t length) PRISM_NONNULL(1);
46
-
47
- /**
48
- * Initialize an owned string that is responsible for freeing allocated memory.
32
+ * Initialize a string that views the given bytes. The bytes are not copied, so
33
+ * they must remain valid for as long as the string is in use.
49
34
  *
50
35
  * @param string The string to initialize.
51
- * @param source The source of the string.
52
- * @param length The length of the string.
36
+ * @param source The start of the bytes.
37
+ * @param length The number of bytes.
53
38
  */
54
- PRISM_EXPORTED_FUNCTION void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length) PRISM_NONNULL(1, 2);
39
+ PRISM_EXPORTED_FUNCTION void pm_string_init(pm_string_t *string, const uint8_t *source, size_t length) PRISM_NONNULL(1);
55
40
 
56
41
  /**
57
42
  * Returns the length associated with the string.
@@ -69,4 +54,8 @@ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string) PRISM
69
54
  */
70
55
  PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string) PRISM_NONNULL(1);
71
56
 
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
72
61
  #endif
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file stringy.hpp
3
+ *
4
+ * Access to the contents of strings from C++.
5
+ */
6
+ #ifndef PRISM_STRINGY_HPP
7
+ #define PRISM_STRINGY_HPP
8
+
9
+ #include "prism/compiler/cplusplus.hpp"
10
+ #include "prism/compiler/lifetimebound.hpp"
11
+
12
+ #include "prism/stringy.h"
13
+
14
+ #include <string_view>
15
+
16
+ namespace prism {
17
+
18
+ /**
19
+ * The bytes of the given string.
20
+ *
21
+ * @param string The string to view.
22
+ * @return A view of the bytes of the string.
23
+ */
24
+ [[nodiscard]] inline std::string_view
25
+ view(const pm_string_t &string PRISM_LIFETIMEBOUND) noexcept {
26
+ return std::string_view(reinterpret_cast<const char *>(pm_string_source(&string)), pm_string_length(&string));
27
+ }
28
+
29
+ }
30
+
31
+ #endif
@@ -8,6 +8,10 @@
8
8
 
9
9
  #include "prism/compiler/exported.h"
10
10
 
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
11
15
  /**
12
16
  * The major version of the Prism library as an int.
13
17
  */
@@ -26,7 +30,7 @@
26
30
  /**
27
31
  * The version of the Prism library as a constant string.
28
32
  */
29
- #define PRISM_VERSION "2.0.0.rc1"
33
+ #define PRISM_VERSION "2.0.0"
30
34
 
31
35
  /**
32
36
  * The prism version and the serialization format.
@@ -35,4 +39,8 @@
35
39
  */
36
40
  PRISM_EXPORTED_FUNCTION const char * pm_version(void);
37
41
 
42
+ #ifdef __cplusplus
43
+ }
44
+ #endif
45
+
38
46
  #endif
data/include/prism.h CHANGED
@@ -6,10 +6,6 @@
6
6
  #ifndef PRISM_H
7
7
  #define PRISM_H
8
8
 
9
- #ifdef __cplusplus
10
- extern "C" {
11
- #endif
12
-
13
9
  #include "prism/arena.h"
14
10
  #include "prism/ast.h"
15
11
  #include "prism/buffer.h"
@@ -124,8 +120,4 @@ extern "C" {
124
120
  * ```
125
121
  */
126
122
 
127
- #ifdef __cplusplus
128
- }
129
- #endif
130
-
131
123
  #endif
data/include/prism.hpp ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @file prism.hpp
3
+ *
4
+ * The main header file for the C++ interface to the prism parser. It adds
5
+ * ownership, checked casts between node types, and callable-based iteration on
6
+ * top of the C API. It never wraps the C structs: every function in it takes
7
+ * and returns the same pm_*_t types that prism.h declares, so the two can be
8
+ * mixed freely. It requires C++17 or later.
9
+ */
10
+ #ifndef PRISM_HPP
11
+ #define PRISM_HPP
12
+
13
+ #include "prism.h"
14
+
15
+ #include "prism/arena.hpp"
16
+ #include "prism/ast.hpp"
17
+ #include "prism/buffer.hpp"
18
+ #include "prism/node.hpp"
19
+ #include "prism/node_type.hpp"
20
+ #include "prism/options.hpp"
21
+ #include "prism/parser.hpp"
22
+ #include "prism/stringy.hpp"
23
+
24
+ #endif
Binary file
Binary file
Binary file
data/lib/prism/ffi.rb CHANGED
@@ -124,6 +124,7 @@ module Prism # :nodoc:
124
124
  "pm_string_query_local",
125
125
  "pm_string_query_constant",
126
126
  "pm_string_query_method_name",
127
+ "pm_string_query_keyword",
127
128
  []
128
129
  )
129
130
 
@@ -722,6 +723,11 @@ module Prism # :nodoc:
722
723
  query(LibRubyParser.pm_string_query_method_name(string, string.bytesize, string.encoding.name))
723
724
  end
724
725
 
726
+ # Mirrors the C extension's StringQuery::keyword? method.
727
+ def keyword?(string)
728
+ query(LibRubyParser.pm_string_query_keyword(string, string.bytesize, string.encoding.name))
729
+ end
730
+
725
731
  private
726
732
 
727
733
  # Parse the enum result and return an appropriate boolean.