rubocop-ast 1.51.0 → 1.52.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/ast/builder.rb +2 -113
  3. data/lib/rubocop/ast/builder_extensions.rb +118 -0
  4. data/lib/rubocop/ast/node.rb +1 -1
  5. data/lib/rubocop/ast/node_pattern/lexer.rex.rb +1 -1
  6. data/lib/rubocop/ast/node_pattern/parser.racc.rb +1 -1
  7. data/lib/rubocop/ast/parser_source.rb +76 -0
  8. data/lib/rubocop/ast/prism_compiler.rb +2106 -0
  9. data/lib/rubocop/ast/prism_lexer.rb +779 -0
  10. data/lib/rubocop/ast/prism_parser.rb +211 -0
  11. data/lib/rubocop/ast/processed_source.rb +26 -27
  12. data/lib/rubocop/ast/sexp.rb +1 -1
  13. data/lib/rubocop/ast/vendor/parser/LICENSE.txt +26 -0
  14. data/lib/rubocop/ast/vendor/parser/ast/node.rb +40 -0
  15. data/lib/rubocop/ast/vendor/parser/clobbering_error.rb +13 -0
  16. data/lib/rubocop/ast/vendor/parser/deprecation.rb +13 -0
  17. data/lib/rubocop/ast/vendor/parser/diagnostic/engine.rb +104 -0
  18. data/lib/rubocop/ast/vendor/parser/diagnostic.rb +163 -0
  19. data/lib/rubocop/ast/vendor/parser/messages.rb +125 -0
  20. data/lib/rubocop/ast/vendor/parser/meta.rb +48 -0
  21. data/lib/rubocop/ast/vendor/parser/source/buffer.rb +369 -0
  22. data/lib/rubocop/ast/vendor/parser/source/comment/associator.rb +233 -0
  23. data/lib/rubocop/ast/vendor/parser/source/comment.rb +134 -0
  24. data/lib/rubocop/ast/vendor/parser/source/map/collection.rb +18 -0
  25. data/lib/rubocop/ast/vendor/parser/source/map/condition.rb +21 -0
  26. data/lib/rubocop/ast/vendor/parser/source/map/constant.rb +32 -0
  27. data/lib/rubocop/ast/vendor/parser/source/map/definition.rb +23 -0
  28. data/lib/rubocop/ast/vendor/parser/source/map/for.rb +19 -0
  29. data/lib/rubocop/ast/vendor/parser/source/map/heredoc.rb +19 -0
  30. data/lib/rubocop/ast/vendor/parser/source/map/index.rb +33 -0
  31. data/lib/rubocop/ast/vendor/parser/source/map/keyword.rb +20 -0
  32. data/lib/rubocop/ast/vendor/parser/source/map/method_definition.rb +25 -0
  33. data/lib/rubocop/ast/vendor/parser/source/map/objc_kwarg.rb +19 -0
  34. data/lib/rubocop/ast/vendor/parser/source/map/operator.rb +17 -0
  35. data/lib/rubocop/ast/vendor/parser/source/map/rescue_body.rb +21 -0
  36. data/lib/rubocop/ast/vendor/parser/source/map/send.rb +36 -0
  37. data/lib/rubocop/ast/vendor/parser/source/map/ternary.rb +18 -0
  38. data/lib/rubocop/ast/vendor/parser/source/map/variable.rb +31 -0
  39. data/lib/rubocop/ast/vendor/parser/source/map.rb +186 -0
  40. data/lib/rubocop/ast/vendor/parser/source/range.rb +326 -0
  41. data/lib/rubocop/ast/vendor/parser/source/tree_rewriter/action.rb +243 -0
  42. data/lib/rubocop/ast/vendor/parser/source/tree_rewriter.rb +431 -0
  43. data/lib/rubocop/ast/vendor/parser/syntax_error.rb +21 -0
  44. data/lib/rubocop/ast/vendor/parser/unknown_encoding_in_magic_comment_error.rb +15 -0
  45. data/lib/rubocop/ast/vendor/parser/version.rb +5 -0
  46. data/lib/rubocop/ast/version.rb +1 -1
  47. data/lib/rubocop/ast.rb +10 -3
  48. metadata +68 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 852caeb016762e91a5ba54a7f395eca116212e1b44024db303924c7991d1b657
4
- data.tar.gz: b4dda6fc3370f3edb5e6f24cebee0b19f2ef4f39274071a07e8a0a0f9255305f
3
+ metadata.gz: 10a0427201ac1703c7cd4860649d1021132e5829adb6b8bb56a42b5d618567c5
4
+ data.tar.gz: 1aaf7f176cc37142421011a587ad5030b410441758b9af4ae5fd86ca3c8fad2f
5
5
  SHA512:
6
- metadata.gz: 07db780992c4c952ce6a32f3dea9e25b86652ebf2c2244adc68048a5a8c4c9fe6afc1dba5450ab68aa76216de794b272ab3c38285f6202f439adf4b70b8a8b24
7
- data.tar.gz: 16c6acc46fffa394620be118f9fcdebd2eaac6293e9ef206123e1f7c6b03d41f6e09844e49441b3734507b9fd87cf7fe8400911c52edf4f8555af5515bcc1513
6
+ metadata.gz: 2dc127a53b8f8f4a1d72ab4a39e6e7e4697f02f142ea94e3b5d8d5e8fb3dfc2ef375b18e8f0628da81e2a46c48813cd1f0d3e113fc920afce5be344996b99284
7
+ data.tar.gz: a429f0e43ae4c558aa166bacca175b78174cf330beee74a231f994b70ef88663194c05f77f4731fbd962a117b500ebfb70caa5d301c3eceffe44676d769cda67
@@ -1,120 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parser'
4
+
3
5
  module RuboCop
4
6
  module AST
5
- # Common functionality between the parser and prism builder
6
- # @api private
7
- module BuilderExtensions
8
- def self.included(base)
9
- base.emit_forward_arg = true
10
- base.emit_match_pattern = true
11
- end
12
-
13
- # @api private
14
- NODE_MAP = {
15
- and: AndNode,
16
- and_asgn: AndAsgnNode,
17
- alias: AliasNode,
18
- arg: ArgNode,
19
- blockarg: ArgNode,
20
- forward_arg: ArgNode,
21
- kwarg: ArgNode,
22
- kwoptarg: ArgNode,
23
- kwrestarg: ArgNode,
24
- optarg: ArgNode,
25
- restarg: ArgNode,
26
- shadowarg: ArgNode,
27
- args: ArgsNode,
28
- array: ArrayNode,
29
- lvasgn: AsgnNode,
30
- ivasgn: AsgnNode,
31
- cvasgn: AsgnNode,
32
- gvasgn: AsgnNode,
33
- block: BlockNode,
34
- numblock: BlockNode,
35
- itblock: BlockNode,
36
- break: BreakNode,
37
- case_match: CaseMatchNode,
38
- casgn: CasgnNode,
39
- case: CaseNode,
40
- class: ClassNode,
41
- complex: ComplexNode,
42
- const: ConstNode,
43
- def: DefNode,
44
- defined?: DefinedNode,
45
- defs: DefNode,
46
- dstr: DstrNode,
47
- ensure: EnsureNode,
48
- for: ForNode,
49
- forward_args: ForwardArgsNode,
50
- forwarded_kwrestarg: KeywordSplatNode,
51
- float: FloatNode,
52
- hash: HashNode,
53
- if: IfNode,
54
- in_pattern: InPatternNode,
55
- int: IntNode,
56
- index: IndexNode,
57
- indexasgn: IndexasgnNode,
58
- irange: RangeNode,
59
- erange: RangeNode,
60
- kwargs: HashNode,
61
- kwbegin: KeywordBeginNode,
62
- kwsplat: KeywordSplatNode,
63
- lambda: LambdaNode,
64
- masgn: MasgnNode,
65
- mlhs: MlhsNode,
66
- module: ModuleNode,
67
- next: NextNode,
68
- op_asgn: OpAsgnNode,
69
- or_asgn: OrAsgnNode,
70
- or: OrNode,
71
- pair: PairNode,
72
- procarg0: Procarg0Node,
73
- rational: RationalNode,
74
- regexp: RegexpNode,
75
- rescue: RescueNode,
76
- resbody: ResbodyNode,
77
- return: ReturnNode,
78
- csend: CsendNode,
79
- send: SendNode,
80
- str: StrNode,
81
- xstr: StrNode,
82
- sclass: SelfClassNode,
83
- super: SuperNode,
84
- zsuper: SuperNode,
85
- sym: SymbolNode,
86
- until: UntilNode,
87
- until_post: UntilNode,
88
- lvar: VarNode,
89
- ivar: VarNode,
90
- cvar: VarNode,
91
- gvar: VarNode,
92
- when: WhenNode,
93
- while: WhileNode,
94
- while_post: WhileNode,
95
- yield: YieldNode
96
- }.freeze
97
-
98
- # Generates {Node} from the given information.
99
- #
100
- # @return [Node] the generated node
101
- def n(type, children, source_map)
102
- node_klass(type).new(type, children, location: source_map)
103
- end
104
-
105
- # Overwrite the base method to allow strings with invalid encoding
106
- # More details here https://github.com/whitequark/parser/issues/283
107
- def string_value(token)
108
- value(token)
109
- end
110
-
111
- private
112
-
113
- def node_klass(type)
114
- NODE_MAP[type] || Node
115
- end
116
- end
117
-
118
7
  # `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
119
8
  # generate ASTs with {RuboCop::AST::Node}.
120
9
  #
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # Common functionality between the parser and prism builder
6
+ # @api private
7
+ module BuilderExtensions
8
+ def self.included(base)
9
+ base.emit_forward_arg = true
10
+ base.emit_match_pattern = true
11
+ end
12
+
13
+ # @api private
14
+ NODE_MAP = {
15
+ and: AndNode,
16
+ and_asgn: AndAsgnNode,
17
+ alias: AliasNode,
18
+ arg: ArgNode,
19
+ blockarg: ArgNode,
20
+ forward_arg: ArgNode,
21
+ kwarg: ArgNode,
22
+ kwoptarg: ArgNode,
23
+ kwrestarg: ArgNode,
24
+ optarg: ArgNode,
25
+ restarg: ArgNode,
26
+ shadowarg: ArgNode,
27
+ args: ArgsNode,
28
+ array: ArrayNode,
29
+ lvasgn: AsgnNode,
30
+ ivasgn: AsgnNode,
31
+ cvasgn: AsgnNode,
32
+ gvasgn: AsgnNode,
33
+ block: BlockNode,
34
+ numblock: BlockNode,
35
+ itblock: BlockNode,
36
+ break: BreakNode,
37
+ case_match: CaseMatchNode,
38
+ casgn: CasgnNode,
39
+ case: CaseNode,
40
+ class: ClassNode,
41
+ complex: ComplexNode,
42
+ const: ConstNode,
43
+ def: DefNode,
44
+ defined?: DefinedNode,
45
+ defs: DefNode,
46
+ dstr: DstrNode,
47
+ ensure: EnsureNode,
48
+ for: ForNode,
49
+ forward_args: ForwardArgsNode,
50
+ forwarded_kwrestarg: KeywordSplatNode,
51
+ float: FloatNode,
52
+ hash: HashNode,
53
+ if: IfNode,
54
+ in_pattern: InPatternNode,
55
+ int: IntNode,
56
+ index: IndexNode,
57
+ indexasgn: IndexasgnNode,
58
+ irange: RangeNode,
59
+ erange: RangeNode,
60
+ kwargs: HashNode,
61
+ kwbegin: KeywordBeginNode,
62
+ kwsplat: KeywordSplatNode,
63
+ lambda: LambdaNode,
64
+ masgn: MasgnNode,
65
+ mlhs: MlhsNode,
66
+ module: ModuleNode,
67
+ next: NextNode,
68
+ op_asgn: OpAsgnNode,
69
+ or_asgn: OrAsgnNode,
70
+ or: OrNode,
71
+ pair: PairNode,
72
+ procarg0: Procarg0Node,
73
+ rational: RationalNode,
74
+ regexp: RegexpNode,
75
+ rescue: RescueNode,
76
+ resbody: ResbodyNode,
77
+ return: ReturnNode,
78
+ csend: CsendNode,
79
+ send: SendNode,
80
+ str: StrNode,
81
+ xstr: StrNode,
82
+ sclass: SelfClassNode,
83
+ super: SuperNode,
84
+ zsuper: SuperNode,
85
+ sym: SymbolNode,
86
+ until: UntilNode,
87
+ until_post: UntilNode,
88
+ lvar: VarNode,
89
+ ivar: VarNode,
90
+ cvar: VarNode,
91
+ gvar: VarNode,
92
+ when: WhenNode,
93
+ while: WhileNode,
94
+ while_post: WhileNode,
95
+ yield: YieldNode
96
+ }.freeze
97
+
98
+ # Generates {Node} from the given information.
99
+ #
100
+ # @return [Node] the generated node
101
+ def n(type, children, source_map)
102
+ node_klass(type).new(type, children, location: source_map)
103
+ end
104
+
105
+ # Overwrite the base method to allow strings with invalid encoding
106
+ # More details here https://github.com/whitequark/parser/issues/283
107
+ def string_value(token)
108
+ value(token)
109
+ end
110
+
111
+ private
112
+
113
+ def node_klass(type)
114
+ NODE_MAP[type] || Node
115
+ end
116
+ end
117
+ end
118
+ end
@@ -246,7 +246,7 @@ module RuboCop
246
246
  # part of it is changed.
247
247
  def updated(type = nil, children = nil, properties = {})
248
248
  properties[:location] ||= @location
249
- klass = RuboCop::AST::Builder::NODE_MAP[type || @type] || Node
249
+ klass = BuilderExtensions::NODE_MAP[type || @type] || Node
250
250
  klass.new(type || @type, children || @children, properties)
251
251
  end
252
252
 
@@ -2,7 +2,7 @@
2
2
  # encoding: UTF-8
3
3
  #--
4
4
  # This file is automatically generated. Do not modify it.
5
- # Generated by: oedipus_lex version 2.6.3.
5
+ # Generated by: oedipus_lex version 2.6.2.
6
6
  # Source: lib/rubocop/ast/node_pattern/lexer.rex
7
7
  #++
8
8
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # DO NOT MODIFY!!!!
4
- # This file is automatically generated by Racc 1.8.1
4
+ # This file is automatically generated by Racc 1.7.3
5
5
  # from Racc grammar file "parser.y".
6
6
  #
7
7
 
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ast'
4
+
5
+ module RuboCop
6
+ module AST
7
+ # Loads the part of the `parser` gem that every parser engine needs: the
8
+ # node base class, the source layer (buffers, ranges, comments, source
9
+ # maps, the tree rewriter) and the diagnostics.
10
+ #
11
+ # They come from the gem when it is installed, because its parsers and
12
+ # builders create objects of the very same classes. Without the gem, a
13
+ # copy of those files that ships with this gem is loaded instead, which is
14
+ # all that the `prism` parser engine needs.
15
+ # @api private
16
+ module ParserSource
17
+ FILES = %w[
18
+ version messages deprecation ast/node meta
19
+ source/buffer source/range source/comment source/comment/associator
20
+ source/tree_rewriter source/tree_rewriter/action
21
+ source/map source/map/operator source/map/collection source/map/constant
22
+ source/map/variable source/map/keyword source/map/definition
23
+ source/map/method_definition source/map/send source/map/index
24
+ source/map/condition source/map/ternary source/map/for
25
+ source/map/rescue_body source/map/heredoc source/map/objc_kwarg
26
+ syntax_error clobbering_error unknown_encoding_in_magic_comment_error
27
+ diagnostic diagnostic/engine
28
+ ].freeze
29
+
30
+ VENDOR_DIR = File.join(__dir__, 'vendor', 'parser')
31
+
32
+ VENDORED = begin
33
+ require 'parser/version'
34
+ false
35
+ rescue LoadError
36
+ true
37
+ end
38
+ private_constant :VENDORED
39
+
40
+ # Whether the classes come from the copy that ships with this gem,
41
+ # which is the case when the `parser` gem is not installed.
42
+ def self.vendored?
43
+ VENDORED
44
+ end
45
+
46
+ def self.ensure_parser_gem(parser_engine)
47
+ return unless vendored?
48
+
49
+ raise LoadError, "The `#{parser_engine}` parser engine needs the `parser` gem. Add it " \
50
+ 'to your Gemfile, or use the `prism` parser engine, which supports ' \
51
+ 'target Ruby versions 3.3 and above.'
52
+ end
53
+
54
+ begin
55
+ FILES.each { |file| require vendored? ? File.join(VENDOR_DIR, file) : "parser/#{file}" }
56
+ rescue LoadError
57
+ # A version of `parser` that lays out its files in another way.
58
+ require 'parser'
59
+ end
60
+
61
+ # Loads the rest of `parser` when something refers to a constant that
62
+ # is not part of the files above, like `Parser::Base` or
63
+ # `Parser::Builders::Default`.
64
+ module LazyConstants
65
+ def const_missing(name)
66
+ return super unless require('parser') && const_defined?(name, false)
67
+
68
+ const_get(name, false)
69
+ end
70
+ end
71
+
72
+ lazy = vendored? ? [] : [::Parser, ::Parser::AST, ::Parser::Source]
73
+ lazy.each { |mod| mod.extend(LazyConstants) }
74
+ end
75
+ end
76
+ end