prism 0.19.0 → 0.24.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -1
  3. data/Makefile +5 -0
  4. data/README.md +9 -6
  5. data/config.yml +236 -38
  6. data/docs/build_system.md +19 -2
  7. data/docs/cruby_compilation.md +27 -0
  8. data/docs/parser_translation.md +34 -0
  9. data/docs/parsing_rules.md +19 -0
  10. data/docs/releasing.md +84 -16
  11. data/docs/ruby_api.md +1 -1
  12. data/docs/ruby_parser_translation.md +19 -0
  13. data/docs/serialization.md +19 -5
  14. data/ext/prism/api_node.c +1989 -1525
  15. data/ext/prism/extension.c +130 -30
  16. data/ext/prism/extension.h +2 -2
  17. data/include/prism/ast.h +1700 -505
  18. data/include/prism/defines.h +8 -0
  19. data/include/prism/diagnostic.h +49 -7
  20. data/include/prism/encoding.h +17 -0
  21. data/include/prism/options.h +40 -14
  22. data/include/prism/parser.h +34 -18
  23. data/include/prism/util/pm_buffer.h +9 -0
  24. data/include/prism/util/pm_constant_pool.h +18 -0
  25. data/include/prism/util/pm_newline_list.h +4 -14
  26. data/include/prism/util/pm_strpbrk.h +4 -1
  27. data/include/prism/version.h +2 -2
  28. data/include/prism.h +19 -2
  29. data/lib/prism/debug.rb +11 -5
  30. data/lib/prism/desugar_compiler.rb +225 -80
  31. data/lib/prism/dot_visitor.rb +36 -14
  32. data/lib/prism/dsl.rb +302 -299
  33. data/lib/prism/ffi.rb +107 -76
  34. data/lib/prism/lex_compat.rb +17 -1
  35. data/lib/prism/node.rb +4580 -2607
  36. data/lib/prism/node_ext.rb +27 -4
  37. data/lib/prism/parse_result.rb +75 -29
  38. data/lib/prism/serialize.rb +633 -305
  39. data/lib/prism/translation/parser/compiler.rb +1838 -0
  40. data/lib/prism/translation/parser/lexer.rb +335 -0
  41. data/lib/prism/translation/parser/rubocop.rb +45 -0
  42. data/lib/prism/translation/parser.rb +190 -0
  43. data/lib/prism/translation/parser33.rb +12 -0
  44. data/lib/prism/translation/parser34.rb +12 -0
  45. data/lib/prism/translation/ripper.rb +696 -0
  46. data/lib/prism/translation/ruby_parser.rb +1521 -0
  47. data/lib/prism/translation.rb +11 -0
  48. data/lib/prism.rb +1 -1
  49. data/prism.gemspec +18 -7
  50. data/rbi/prism.rbi +150 -88
  51. data/rbi/prism_static.rbi +15 -3
  52. data/sig/prism.rbs +996 -961
  53. data/sig/prism_static.rbs +123 -46
  54. data/src/diagnostic.c +264 -219
  55. data/src/encoding.c +21 -26
  56. data/src/node.c +2 -6
  57. data/src/options.c +29 -5
  58. data/src/prettyprint.c +176 -44
  59. data/src/prism.c +1499 -564
  60. data/src/serialize.c +35 -21
  61. data/src/token_type.c +353 -4
  62. data/src/util/pm_buffer.c +11 -0
  63. data/src/util/pm_constant_pool.c +37 -11
  64. data/src/util/pm_newline_list.c +6 -15
  65. data/src/util/pm_string.c +0 -7
  66. data/src/util/pm_strpbrk.c +122 -14
  67. metadata +16 -5
  68. data/docs/building.md +0 -29
  69. data/lib/prism/ripper_compat.rb +0 -207
data/sig/prism_static.rbs CHANGED
@@ -1,32 +1,79 @@
1
1
  module Prism
2
- class ParseResult
3
- def value: () -> ProgramNode
4
- def comments: () -> Array[Comment]
5
- def errors: () -> Array[ParseError]
6
- def warnings: () -> Array[ParseWarning]
7
- def source: () -> Source
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
8
40
  end
9
41
 
10
42
  class ParseError
11
- def message: () -> String
12
- def location: () -> Location
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 }
13
48
  end
14
49
 
15
50
  class ParseWarning
16
- def message: () -> String
17
- def location: () -> Location
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 }
18
56
  end
19
57
 
20
58
  class Node
59
+ @newline: bool
60
+
61
+ attr_reader location: Location
62
+
21
63
  def child_nodes: () -> Array[Node?]
22
- def location: () -> Location
64
+ def newline?: () -> bool
65
+ def set_newline_flag: (Array[bool] newline_marked) -> void
23
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
24
69
  def to_dot: () -> String
25
70
  end
26
71
 
27
72
  class Comment
28
- def location: () -> Location
29
- def trailing?: () -> bool
73
+ attr_reader location: Location
74
+
75
+ def initialize: (Location location) -> void
76
+ def deconstruct_keys: (Array[Symbol] keys) -> { location: Location }
30
77
  end
31
78
 
32
79
  class InlineComment < Comment
@@ -34,22 +81,45 @@ module Prism
34
81
  end
35
82
 
36
83
  class EmbDocComment < Comment
84
+ def trailing?: () -> false
37
85
  end
38
86
 
39
- class DATAComment < Comment
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 }
40
97
  end
41
98
 
42
99
  class Location
43
- def initialize: (source: Source, start_offset: Integer, length: Integer) -> void
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
44
107
  def slice: () -> String
45
- def comments: () -> Array[Comment]
46
- def copy: (**untyped) -> Location
47
- def start_offset: () -> Integer
108
+ def start_character_offset: () -> Integer
48
109
  def end_offset: () -> Integer
110
+ def end_character_offset: () -> Integer
49
111
  def start_line: () -> Integer
112
+ def start_line_slice: () -> String
50
113
  def end_line: () -> Integer
51
114
  def start_column: () -> Integer
115
+ def start_character_column: () -> Integer
52
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
53
123
  end
54
124
 
55
125
  class Source
@@ -57,30 +127,24 @@ module Prism
57
127
  attr_reader start_line: Integer
58
128
  attr_reader offsets: Array[Integer]
59
129
 
60
- @source: String
61
- @start_line: Integer
62
- @offsets: Array[Integer]
63
-
64
- def initialize: (source: String, start_line: Integer, offsets: Array[Integer]) -> void
65
- def slice: (offset: Integer, length: Integer) -> String
66
- def line: (value: Integer) -> Integer
67
- def line_offset: (value: Integer) -> Integer
68
- def column: (value: Integer) -> Integer
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
69
137
  end
70
138
 
71
139
  class Token
72
- attr_reader type: untyped
140
+ attr_reader type: Symbol
73
141
  attr_reader value: String
74
142
  attr_reader location: Location
75
143
 
76
- @type: untyped
77
- @value: String
78
- @location: Location
79
-
80
- def initialize: (type: untyped, value: String, location: Location) -> void
81
- def deconstruct_keys: (keys: untyped) -> untyped
82
- def pretty_print: (q: untyped) -> untyped
83
- def ==: (other: untyped) -> bool
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
84
148
  end
85
149
 
86
150
  class NodeInspector
@@ -90,35 +154,48 @@ module Prism
90
154
  @prefix: String
91
155
  @output: String
92
156
 
93
- def initialize: (prefix: String) -> void
157
+ def initialize: (?String prefix) -> void
94
158
 
95
159
  # Appends a line to the output with the current prefix.
96
- def <<: (line: String) -> void
160
+ def <<: (String line) -> void
97
161
 
98
162
  # This generates a string that is used as the header of the inspect output
99
163
  # for any given node.
100
- def header: (node: Node) -> String
164
+ def header: (Node node) -> String
101
165
 
102
166
  # Generates a string that represents a list of nodes. It handles properly
103
167
  # using the box drawing characters to make the output look nice.
104
- def list: (prefix: String, nodes: Array[Node]) -> String
168
+ def list: (String prefix, Array[Node] nodes) -> String
105
169
 
106
170
  # Generates a string that represents a location field on a node.
107
- def location: (value: Location) -> String
171
+ def location: (Location? value) -> String
108
172
 
109
173
  # Generates a string that represents a child node.
110
- def child_node: (node: Node, append: String) -> String
174
+ def child_node: (Node node, String append) -> String
111
175
 
112
176
  # Returns a new inspector that can be used to inspect a child node.
113
- def child_inspector: (append: String) -> NodeInspector
177
+ def child_inspector: (String append) -> NodeInspector
114
178
 
115
179
  # Returns the output as a string.
116
180
  def to_str: () -> String
117
181
  end
118
182
 
119
183
  class BasicVisitor
120
- def visit: (node: Node?) -> void
121
- def visit_all: (nodes: Array[Node?]) -> void
122
- def visit_child_nodes: (node: Node) -> void
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
123
200
  end
124
201
  end