prism 1.8.1 → 2.0.0.rc1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +90 -2
- data/Makefile +41 -12
- data/README.md +35 -97
- data/config.yml +174 -163
- data/docs/build_system.md +2 -2
- data/docs/configuration.md +5 -4
- data/docs/encoding.md +2 -2
- data/docs/fuzzing.md +4 -11
- data/docs/javascript.md +19 -4
- data/docs/mapping.md +1 -1
- data/docs/releasing.md +77 -5
- data/docs/relocation.md +2 -4
- data/docs/ripper_translation.md +8 -17
- data/docs/serialization.md +21 -24
- data/docs/testing.md +46 -29
- data/ext/prism/api_node.c +1461 -1401
- data/ext/prism/extconf.rb +3 -4
- data/ext/prism/extension.c +778 -422
- data/ext/prism/extension.h +3 -3
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +2729 -612
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +24 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +38 -405
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +91 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +984 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +18 -53
- data/include/prism/options.h +146 -280
- data/include/prism/parser.h +336 -868
- data/include/prism/prettyprint.h +6 -9
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +63 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +13 -4
- data/include/prism.h +43 -320
- data/lib/prism/compiler.rb +319 -305
- data/lib/prism/desugar_compiler.rb +105 -34
- data/lib/prism/dispatcher.rb +646 -473
- data/lib/prism/dot_visitor.rb +592 -511
- data/lib/prism/dsl.rb +391 -25
- data/lib/prism/ffi.rb +252 -90
- data/lib/prism/inspect_visitor.rb +357 -325
- data/lib/prism/lex_compat.rb +311 -228
- data/lib/prism/mutation_compiler.rb +313 -305
- data/lib/prism/node.rb +20284 -7038
- data/lib/prism/node_ext.rb +180 -187
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +7 -1
- data/lib/prism/parse_result/newlines.rb +276 -8
- data/lib/prism/parse_result.rb +462 -139
- data/lib/prism/pattern.rb +65 -20
- data/lib/prism/reflection.rb +23 -12
- data/lib/prism/relocation.rb +149 -87
- data/lib/prism/serialize.rb +3442 -536
- data/lib/prism/string_query.rb +16 -1
- data/lib/prism/translation/parser/builder.rb +10 -2
- data/lib/prism/translation/parser/compiler.rb +44 -52
- data/lib/prism/translation/parser/lexer.rb +41 -92
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/parser_current.rb +1 -1
- data/lib/prism/translation/ripper/filter.rb +53 -0
- data/lib/prism/translation/ripper/lexer.rb +92 -5
- data/lib/prism/translation/ripper/sexp.rb +2 -10
- data/lib/prism/translation/ripper/shim.rb +2 -0
- data/lib/prism/translation/ripper.rb +1005 -224
- data/lib/prism/translation/ruby_parser.rb +73 -316
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +632 -5
- data/lib/prism.rb +79 -22
- data/prism.gemspec +123 -61
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +13681 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +764 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +181 -0
- data/rbi/generated/prism/string_query.rbi +36 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser_versions.rbi +5 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
- data/sig/generated/prism/node.rbs +20160 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +859 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +195 -0
- data/sig/generated/prism/string_query.rbs +36 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/{util/pm_buffer.c → buffer.c} +44 -21
- data/src/{util/pm_char.c → char.c} +28 -57
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +93 -65
- data/src/encoding.c +8 -3
- data/src/errors_format.c +519 -0
- data/src/{util/pm_integer.c → integer.c} +33 -22
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/src/node.c +3504 -7674
- data/src/options.c +162 -49
- data/src/parser.c +349 -0
- data/src/prettyprint.c +421 -354
- data/src/prism.c +8035 -7019
- data/src/regexp.c +961 -45
- data/src/serialize.c +459 -424
- data/src/source.c +518 -0
- data/src/static_literals.c +111 -43
- data/src/string_query.c +166 -0
- data/src/stringy.c +91 -0
- data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/src/strpbrk.c +447 -0
- data/src/{token_type.c → tokens.c} +39 -18
- metadata +123 -62
- data/ext/prism/api_pack.c +0 -276
- data/include/prism/defines.h +0 -260
- data/include/prism/pack.h +0 -163
- data/include/prism/regexp.h +0 -43
- data/include/prism/util/pm_buffer.h +0 -236
- data/include/prism/util/pm_char.h +0 -204
- data/include/prism/util/pm_constant_pool.h +0 -218
- data/include/prism/util/pm_integer.h +0 -130
- data/include/prism/util/pm_memchr.h +0 -29
- data/include/prism/util/pm_newline_list.h +0 -113
- data/include/prism/util/pm_string.h +0 -200
- data/lib/prism/lex_ripper.rb +0 -64
- data/lib/prism/pack.rb +0 -230
- data/lib/prism/parse_result/comments.rb +0 -188
- data/rbi/prism/compiler.rbi +0 -12
- data/rbi/prism/dsl.rbi +0 -524
- data/rbi/prism/inspect_visitor.rbi +0 -12
- data/rbi/prism/node.rbi +0 -8747
- data/rbi/prism/node_ext.rbi +0 -107
- data/rbi/prism/parse_result.rbi +0 -404
- data/rbi/prism/reflection.rbi +0 -58
- data/rbi/prism/string_query.rbi +0 -12
- data/rbi/prism/visitor.rbi +0 -473
- data/rbi/prism.rbi +0 -66
- data/sig/prism/compiler.rbs +0 -9
- data/sig/prism/dispatcher.rbs +0 -19
- data/sig/prism/dot_visitor.rbs +0 -6
- data/sig/prism/dsl.rbs +0 -351
- data/sig/prism/inspect_visitor.rbs +0 -22
- data/sig/prism/lex_compat.rbs +0 -10
- data/sig/prism/node.rbs +0 -4039
- data/sig/prism/node_ext.rbs +0 -149
- data/sig/prism/pack.rbs +0 -43
- data/sig/prism/parse_result/comments.rbs +0 -38
- data/sig/prism/parse_result.rbs +0 -196
- data/sig/prism/pattern.rbs +0 -13
- data/sig/prism/reflection.rbs +0 -50
- data/sig/prism/relocation.rbs +0 -185
- data/sig/prism/serialize.rbs +0 -8
- data/sig/prism/string_query.rbs +0 -11
- data/sig/prism/visitor.rbs +0 -169
- data/sig/prism.rbs +0 -258
- data/src/pack.c +0 -509
- data/src/util/pm_constant_pool.c +0 -342
- data/src/util/pm_list.c +0 -49
- data/src/util/pm_newline_list.c +0 -125
- data/src/util/pm_string.c +0 -381
- data/src/util/pm_strpbrk.c +0 -206
|
@@ -6,10 +6,8 @@ require_relative "../ripper"
|
|
|
6
6
|
module Prism
|
|
7
7
|
module Translation
|
|
8
8
|
class Ripper
|
|
9
|
-
class Lexer # :nodoc:
|
|
10
|
-
# :
|
|
11
|
-
class State
|
|
12
|
-
|
|
9
|
+
class Lexer < Ripper # :nodoc:
|
|
10
|
+
class State # :nodoc:
|
|
13
11
|
attr_reader :to_int, :to_s
|
|
14
12
|
|
|
15
13
|
def initialize(i)
|
|
@@ -38,8 +36,97 @@ module Prism
|
|
|
38
36
|
def allbits?(i) to_int.allbits?(i) end
|
|
39
37
|
def anybits?(i) to_int.anybits?(i) end
|
|
40
38
|
def nobits?(i) to_int.nobits?(i) end
|
|
39
|
+
|
|
40
|
+
# Instances are frozen and there are only a handful of them so we
|
|
41
|
+
# cache them here.
|
|
42
|
+
STATES = Hash.new { |hash, key| hash[key] = State.new(key) }
|
|
43
|
+
private_constant :STATES
|
|
44
|
+
|
|
45
|
+
def self.[](i)
|
|
46
|
+
STATES[i]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class Elem # :nodoc:
|
|
51
|
+
attr_accessor :pos, :event, :tok, :state, :message
|
|
52
|
+
|
|
53
|
+
def initialize(pos, event, tok, state, message = nil)
|
|
54
|
+
@pos = pos
|
|
55
|
+
@event = event
|
|
56
|
+
@tok = tok
|
|
57
|
+
@state = State[state]
|
|
58
|
+
@message = message
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def [](index)
|
|
62
|
+
case index
|
|
63
|
+
when 0, :pos
|
|
64
|
+
@pos
|
|
65
|
+
when 1, :event
|
|
66
|
+
@event
|
|
67
|
+
when 2, :tok
|
|
68
|
+
@tok
|
|
69
|
+
when 3, :state
|
|
70
|
+
@state
|
|
71
|
+
when 4, :message
|
|
72
|
+
@message
|
|
73
|
+
else
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def inspect
|
|
79
|
+
"#<#{self.class}: #{event}@#{pos[0]}:#{pos[1]}:#{state}: #{tok.inspect}#{": " if message}#{message}>"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
alias to_s inspect
|
|
83
|
+
|
|
84
|
+
def pretty_print(q)
|
|
85
|
+
q.group(2, "#<#{self.class}:", ">") {
|
|
86
|
+
q.breakable
|
|
87
|
+
q.text("#{event}@#{pos[0]}:#{pos[1]}")
|
|
88
|
+
q.breakable
|
|
89
|
+
state.pretty_print(q)
|
|
90
|
+
q.breakable
|
|
91
|
+
q.text("token: ")
|
|
92
|
+
tok.pretty_print(q)
|
|
93
|
+
if message
|
|
94
|
+
q.breakable
|
|
95
|
+
q.text("message: ")
|
|
96
|
+
q.text(message)
|
|
97
|
+
end
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def to_a
|
|
102
|
+
if @message
|
|
103
|
+
[@pos, @event, @tok, @state, @message]
|
|
104
|
+
else
|
|
105
|
+
[@pos, @event, @tok, @state]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Pretty much just the same as Prism.lex_compat.
|
|
111
|
+
def lex(raise_errors: false)
|
|
112
|
+
Ripper.lex(@source, filename, lineno, raise_errors: raise_errors)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Returns the lex_compat result wrapped in `Elem`. Errors are omitted.
|
|
116
|
+
# Since ripper is a streaming parser, tokens are expected to be emitted in the order
|
|
117
|
+
# that the parser encounters them. This is not implemented.
|
|
118
|
+
def parse(...)
|
|
119
|
+
lex(...).map do |position, event, token, state|
|
|
120
|
+
Elem.new(position, event, token, state.to_int)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Similar to parse but ripper sorts the elements by position in the source. Also
|
|
125
|
+
# includes errors. Since prism does error recovery, in cases of syntax errors
|
|
126
|
+
# the result may differ greatly compared to ripper.
|
|
127
|
+
def scan(...)
|
|
128
|
+
parse(...)
|
|
41
129
|
end
|
|
42
|
-
# :startdoc:
|
|
43
130
|
end
|
|
44
131
|
end
|
|
45
132
|
end
|
|
@@ -8,9 +8,7 @@ module Prism
|
|
|
8
8
|
class Ripper
|
|
9
9
|
# This class mirrors the ::Ripper::SexpBuilder subclass of ::Ripper that
|
|
10
10
|
# returns the arrays of [type, *children].
|
|
11
|
-
class SexpBuilder < Ripper
|
|
12
|
-
# :stopdoc:
|
|
13
|
-
|
|
11
|
+
class SexpBuilder < Ripper # :nodoc:
|
|
14
12
|
attr_reader :error
|
|
15
13
|
|
|
16
14
|
private
|
|
@@ -65,16 +63,12 @@ module Prism
|
|
|
65
63
|
remove_method :on_parse_error
|
|
66
64
|
alias on_parse_error on_error
|
|
67
65
|
alias compile_error on_error
|
|
68
|
-
|
|
69
|
-
# :startdoc:
|
|
70
66
|
end
|
|
71
67
|
|
|
72
68
|
# This class mirrors the ::Ripper::SexpBuilderPP subclass of ::Ripper that
|
|
73
69
|
# returns the same values as ::Ripper::SexpBuilder except with a couple of
|
|
74
70
|
# niceties that flatten linked lists into arrays.
|
|
75
|
-
class SexpBuilderPP < SexpBuilder
|
|
76
|
-
# :stopdoc:
|
|
77
|
-
|
|
71
|
+
class SexpBuilderPP < SexpBuilder # :nodoc:
|
|
78
72
|
private
|
|
79
73
|
|
|
80
74
|
def on_heredoc_dedent(val, width)
|
|
@@ -118,8 +112,6 @@ module Prism
|
|
|
118
112
|
alias_method "on_#{event}", :_dispatch_event_push
|
|
119
113
|
end
|
|
120
114
|
end
|
|
121
|
-
|
|
122
|
-
# :startdoc:
|
|
123
115
|
end
|
|
124
116
|
end
|
|
125
117
|
end
|