prism 0.24.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +132 -1
  4. data/Makefile +25 -18
  5. data/README.md +45 -6
  6. data/config.yml +828 -25
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +4 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +7 -9
  12. data/docs/ripper_translation.md +50 -0
  13. data/docs/ruby_api.md +1 -0
  14. data/docs/serialization.md +26 -5
  15. data/ext/prism/api_node.c +1037 -936
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +62 -18
  18. data/ext/prism/extension.c +351 -71
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +539 -101
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +168 -74
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +84 -9
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +213 -54
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +120 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +8 -0
  35. data/include/prism/util/pm_string.h +26 -2
  36. data/include/prism/version.h +2 -2
  37. data/include/prism.h +59 -1
  38. data/lib/prism/compiler.rb +8 -1
  39. data/lib/prism/debug.rb +46 -3
  40. data/lib/prism/desugar_compiler.rb +5 -3
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +141 -54
  43. data/lib/prism/dsl.rb +48 -36
  44. data/lib/prism/ffi.rb +82 -17
  45. data/lib/prism/inspect_visitor.rb +2156 -0
  46. data/lib/prism/lex_compat.rb +34 -15
  47. data/lib/prism/mutation_compiler.rb +13 -2
  48. data/lib/prism/node.rb +4453 -4459
  49. data/lib/prism/node_ext.rb +249 -30
  50. data/lib/prism/pack.rb +4 -0
  51. data/lib/prism/parse_result/comments.rb +35 -18
  52. data/lib/prism/parse_result/newlines.rb +2 -2
  53. data/lib/prism/parse_result.rb +218 -43
  54. data/lib/prism/pattern.rb +28 -10
  55. data/lib/prism/polyfill/byteindex.rb +13 -0
  56. data/lib/prism/polyfill/unpack1.rb +14 -0
  57. data/lib/prism/reflection.rb +411 -0
  58. data/lib/prism/serialize.rb +480 -112
  59. data/lib/prism/translation/parser/compiler.rb +376 -88
  60. data/lib/prism/translation/parser/lexer.rb +103 -22
  61. data/lib/prism/translation/parser/rubocop.rb +41 -13
  62. data/lib/prism/translation/parser.rb +123 -11
  63. data/lib/prism/translation/parser33.rb +1 -1
  64. data/lib/prism/translation/parser34.rb +1 -1
  65. data/lib/prism/translation/ripper/sexp.rb +125 -0
  66. data/lib/prism/translation/ripper/shim.rb +5 -0
  67. data/lib/prism/translation/ripper.rb +3216 -462
  68. data/lib/prism/translation/ruby_parser.rb +111 -56
  69. data/lib/prism/translation.rb +3 -1
  70. data/lib/prism/visitor.rb +10 -0
  71. data/lib/prism.rb +12 -20
  72. data/prism.gemspec +46 -14
  73. data/rbi/prism/compiler.rbi +12 -0
  74. data/rbi/prism/inspect_visitor.rbi +12 -0
  75. data/rbi/prism/node.rbi +8712 -0
  76. data/rbi/prism/node_ext.rbi +107 -0
  77. data/rbi/prism/parse_result.rbi +358 -0
  78. data/rbi/prism/reflection.rbi +58 -0
  79. data/rbi/prism/translation/parser.rbi +11 -0
  80. data/rbi/prism/translation/parser33.rbi +6 -0
  81. data/rbi/prism/translation/parser34.rbi +6 -0
  82. data/rbi/prism/translation/ripper.rbi +15 -0
  83. data/rbi/prism/visitor.rbi +470 -0
  84. data/rbi/prism.rbi +38 -7748
  85. data/sig/prism/compiler.rbs +9 -0
  86. data/sig/prism/dispatcher.rbs +16 -0
  87. data/sig/prism/dot_visitor.rbs +6 -0
  88. data/sig/prism/dsl.rbs +462 -0
  89. data/sig/prism/inspect_visitor.rbs +22 -0
  90. data/sig/prism/lex_compat.rbs +10 -0
  91. data/sig/prism/mutation_compiler.rbs +158 -0
  92. data/sig/prism/node.rbs +3558 -0
  93. data/sig/prism/node_ext.rbs +82 -0
  94. data/sig/prism/pack.rbs +43 -0
  95. data/sig/prism/parse_result.rbs +160 -0
  96. data/sig/prism/pattern.rbs +13 -0
  97. data/sig/prism/reflection.rbs +50 -0
  98. data/sig/prism/serialize.rbs +6 -0
  99. data/sig/prism/visitor.rbs +168 -0
  100. data/sig/prism.rbs +188 -4767
  101. data/src/diagnostic.c +636 -230
  102. data/src/encoding.c +211 -108
  103. data/src/node.c +7555 -451
  104. data/src/options.c +66 -31
  105. data/src/pack.c +33 -17
  106. data/src/prettyprint.c +1383 -1431
  107. data/src/prism.c +4734 -1310
  108. data/src/regexp.c +17 -2
  109. data/src/serialize.c +68 -46
  110. data/src/static_literals.c +638 -0
  111. data/src/token_type.c +10 -9
  112. data/src/util/pm_buffer.c +147 -20
  113. data/src/util/pm_char.c +4 -4
  114. data/src/util/pm_constant_pool.c +35 -11
  115. data/src/util/pm_integer.c +642 -0
  116. data/src/util/pm_list.c +1 -1
  117. data/src/util/pm_newline_list.c +14 -5
  118. data/src/util/pm_string.c +134 -5
  119. data/src/util/pm_string_list.c +2 -2
  120. metadata +41 -9
  121. data/docs/ripper.md +0 -36
  122. data/include/prism/util/pm_state_stack.h +0 -42
  123. data/lib/prism/node_inspector.rb +0 -68
  124. data/rbi/prism_static.rbi +0 -207
  125. data/sig/prism_static.rbs +0 -201
  126. data/src/util/pm_state_stack.c +0 -25
data/sig/prism_static.rbs DELETED
@@ -1,201 +0,0 @@
1
- module Prism
2
- BACKEND: :CEXT | :FFI
3
- VERSION: String
4
-
5
- def self.parse: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
6
- def self.lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
7
- def self.parse_lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
8
- def self.dump: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> String
9
- def self.parse_comments: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
10
- def self.parse_success?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
11
- def self.parse_failure?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
12
-
13
- def self.parse_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
14
- def self.lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
15
- def self.parse_lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
16
- def self.dump_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> String
17
- def self.parse_file_comments: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
18
- def self.parse_file_failure?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
19
- def self.parse_file_success?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
20
-
21
- def self.load: (String source, String serialized) -> ParseResult[ProgramNode]
22
-
23
- type ripper_token = [[Integer, Integer], Symbol, String, untyped]
24
- def self.lex_compat: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[ripper_token]]
25
- def self.lex_ripper: (String source) -> Array[ripper_token]
26
-
27
- class ParseResult[T]
28
- attr_reader value: T
29
- attr_reader comments: Array[Comment]
30
- attr_reader magic_comments: Array[MagicComment]
31
- attr_reader data_loc: Location?
32
- attr_reader errors: Array[ParseError]
33
- attr_reader warnings: Array[ParseWarning]
34
- attr_reader source: Source
35
-
36
- def initialize: (T value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
37
- def deconstruct_keys: (Array[Symbol] keys) -> { value: T, comments: Array[Comment], magic_comments: Array[MagicComment], data_loc: Location?, errors: Array[ParseError], warnings: Array[ParseWarning] }
38
- def success?: () -> bool
39
- def failure?: () -> bool
40
- end
41
-
42
- class ParseError
43
- attr_reader message: String
44
- attr_reader location: Location
45
-
46
- def initialize: (String message, Location location) -> void
47
- def deconstruct_keys: (Array[Symbol] keys) -> { message: String, location: Location }
48
- end
49
-
50
- class ParseWarning
51
- attr_reader message: String
52
- attr_reader location: Location
53
-
54
- def initialize: (String message, Location location) -> void
55
- def deconstruct_keys: (Array[Symbol] keys) -> { message: String, location: Location }
56
- end
57
-
58
- class Node
59
- @newline: bool
60
-
61
- attr_reader location: Location
62
-
63
- def child_nodes: () -> Array[Node?]
64
- def newline?: () -> bool
65
- def set_newline_flag: (Array[bool] newline_marked) -> void
66
- def slice: () -> String
67
- def pretty_print: (untyped q) -> untyped
68
- def inspect: (?NodeInspector inspector) -> String # TODO: not right, only is defined on subclasses
69
- def to_dot: () -> String
70
- end
71
-
72
- class Comment
73
- attr_reader location: Location
74
-
75
- def initialize: (Location location) -> void
76
- def deconstruct_keys: (Array[Symbol] keys) -> { location: Location }
77
- end
78
-
79
- class InlineComment < Comment
80
- def trailing?: () -> bool
81
- end
82
-
83
- class EmbDocComment < Comment
84
- def trailing?: () -> false
85
- end
86
-
87
- class MagicComment
88
- attr_reader key_loc: Location
89
- attr_reader value_loc: Location
90
-
91
- def initialize: (Location key_loc, Location value_loc) -> void
92
-
93
- def key: () -> String
94
- def value: () -> String
95
-
96
- def deconstruct_keys: (Array[Symbol] keys) -> { key_loc: Location, value_loc: Location }
97
- end
98
-
99
- class Location
100
- attr_reader source: Source | nil
101
- attr_reader start_offset: Integer
102
- attr_reader length: Integer
103
- attr_reader comments: Array[Comment]
104
-
105
- def initialize: (Source? source, Integer start_offset, Integer length) -> void
106
- def copy: (?source: Source, ?start_offset: Integer, ?length: Integer) -> Location
107
- def slice: () -> String
108
- def start_character_offset: () -> Integer
109
- def end_offset: () -> Integer
110
- def end_character_offset: () -> Integer
111
- def start_line: () -> Integer
112
- def start_line_slice: () -> String
113
- def end_line: () -> Integer
114
- def start_column: () -> Integer
115
- def start_character_column: () -> Integer
116
- def end_column: () -> Integer
117
- def end_character_column: () -> Integer
118
- def deconstruct_keys: (Array[Symbol] keys) -> { start_offset: Integer, end_offset: Integer }
119
- def pretty_print: (untyped q) -> untyped
120
- def join: (Location other) -> Location
121
-
122
- def self.null: () -> Location
123
- end
124
-
125
- class Source
126
- attr_reader source: String
127
- attr_reader start_line: Integer
128
- attr_reader offsets: Array[Integer]
129
-
130
- def initialize: (String source, ?Integer start_line, ?Array[Integer] offsets) -> void
131
- def slice: (Integer byte_offset, Integer length) -> String
132
- def line: (Integer byte_offset) -> Integer
133
- def line_offset: (Integer byte_offset) -> Integer
134
- def column: (Integer byte_offset) -> Integer
135
- def character_offset: (Integer byte_offset) -> Integer
136
- def character_column: (Integer byte_offset) -> Integer
137
- end
138
-
139
- class Token
140
- attr_reader type: Symbol
141
- attr_reader value: String
142
- attr_reader location: Location
143
-
144
- def initialize: (Symbol type, String value, Location location) -> void
145
- def deconstruct_keys: (Array[Symbol] keys) -> { type: Symbol, value: String, location: Location }
146
- def pretty_print: (untyped q) -> untyped
147
- def ==: (untyped other) -> bool
148
- end
149
-
150
- class NodeInspector
151
- attr_reader prefix: String
152
- attr_reader output: String
153
-
154
- @prefix: String
155
- @output: String
156
-
157
- def initialize: (?String prefix) -> void
158
-
159
- # Appends a line to the output with the current prefix.
160
- def <<: (String line) -> void
161
-
162
- # This generates a string that is used as the header of the inspect output
163
- # for any given node.
164
- def header: (Node node) -> String
165
-
166
- # Generates a string that represents a list of nodes. It handles properly
167
- # using the box drawing characters to make the output look nice.
168
- def list: (String prefix, Array[Node] nodes) -> String
169
-
170
- # Generates a string that represents a location field on a node.
171
- def location: (Location? value) -> String
172
-
173
- # Generates a string that represents a child node.
174
- def child_node: (Node node, String append) -> String
175
-
176
- # Returns a new inspector that can be used to inspect a child node.
177
- def child_inspector: (String append) -> NodeInspector
178
-
179
- # Returns the output as a string.
180
- def to_str: () -> String
181
- end
182
-
183
- class BasicVisitor
184
- def visit: (Node? node) -> void
185
- def visit_all: (Array[Node?] nodes) -> void
186
- def visit_child_nodes: (Node node) -> void
187
- end
188
-
189
- class Pattern
190
- class CompilationError < StandardError
191
- end
192
-
193
- attr_reader query: String
194
-
195
- @compiled: Proc
196
-
197
- def initialize: (String query) -> void
198
- def compile: () -> Proc
199
- def scan: (Node root) -> void
200
- end
201
- end
@@ -1,25 +0,0 @@
1
- #include "prism/util/pm_state_stack.h"
2
-
3
- /**
4
- * Pushes a value onto the stack.
5
- */
6
- void
7
- pm_state_stack_push(pm_state_stack_t *stack, bool value) {
8
- *stack = (*stack << 1) | (value & 1);
9
- }
10
-
11
- /**
12
- * Pops a value off the stack.
13
- */
14
- void
15
- pm_state_stack_pop(pm_state_stack_t *stack) {
16
- *stack >>= 1;
17
- }
18
-
19
- /**
20
- * Returns the value at the top of the stack.
21
- */
22
- bool
23
- pm_state_stack_p(pm_state_stack_t *stack) {
24
- return *stack & 1;
25
- }