parser 2.6.0.0 → 3.1.0.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser/all.rb +3 -0
  3. data/lib/parser/ast/processor.rb +48 -1
  4. data/lib/parser/base.rb +30 -6
  5. data/lib/parser/builders/default.rb +670 -38
  6. data/lib/parser/context.rb +24 -26
  7. data/lib/parser/current.rb +36 -9
  8. data/lib/parser/current_arg_stack.rb +46 -0
  9. data/lib/parser/diagnostic/engine.rb +1 -2
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/lexer/dedenter.rb +58 -49
  12. data/lib/parser/lexer/explanation.rb +1 -1
  13. data/lib/parser/lexer.rb +13837 -11893
  14. data/lib/parser/macruby.rb +2544 -2489
  15. data/lib/parser/max_numparam_stack.rb +56 -0
  16. data/lib/parser/messages.rb +78 -44
  17. data/lib/parser/meta.rb +13 -3
  18. data/lib/parser/ruby18.rb +2313 -2259
  19. data/lib/parser/ruby19.rb +2537 -2488
  20. data/lib/parser/ruby20.rb +2724 -2673
  21. data/lib/parser/ruby21.rb +2766 -2727
  22. data/lib/parser/ruby22.rb +2683 -2628
  23. data/lib/parser/ruby23.rb +2796 -2755
  24. data/lib/parser/ruby24.rb +2812 -2771
  25. data/lib/parser/ruby25.rb +2703 -2670
  26. data/lib/parser/ruby26.rb +2794 -2747
  27. data/lib/parser/ruby27.rb +7914 -0
  28. data/lib/parser/ruby28.rb +8047 -0
  29. data/lib/parser/ruby30.rb +8096 -0
  30. data/lib/parser/ruby31.rb +8354 -0
  31. data/lib/parser/rubymotion.rb +2527 -2485
  32. data/lib/parser/runner/ruby_parse.rb +2 -2
  33. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  34. data/lib/parser/runner.rb +36 -2
  35. data/lib/parser/source/buffer.rb +53 -28
  36. data/lib/parser/source/comment/associator.rb +31 -8
  37. data/lib/parser/source/comment.rb +14 -1
  38. data/lib/parser/source/map/method_definition.rb +25 -0
  39. data/lib/parser/source/range.rb +19 -3
  40. data/lib/parser/source/tree_rewriter/action.rb +137 -28
  41. data/lib/parser/source/tree_rewriter.rb +144 -14
  42. data/lib/parser/static_environment.rb +23 -0
  43. data/lib/parser/tree_rewriter.rb +3 -3
  44. data/lib/parser/variables_stack.rb +36 -0
  45. data/lib/parser/version.rb +1 -1
  46. data/lib/parser.rb +4 -0
  47. data/parser.gemspec +12 -19
  48. metadata +34 -99
  49. data/.gitignore +0 -32
  50. data/.travis.yml +0 -45
  51. data/.yardopts +0 -21
  52. data/CHANGELOG.md +0 -943
  53. data/CONTRIBUTING.md +0 -17
  54. data/Gemfile +0 -10
  55. data/README.md +0 -301
  56. data/Rakefile +0 -165
  57. data/ci/run_rubocop_specs +0 -14
  58. data/doc/AST_FORMAT.md +0 -1735
  59. data/doc/CUSTOMIZATION.md +0 -37
  60. data/doc/INTERNALS.md +0 -21
  61. data/doc/css/.gitkeep +0 -0
  62. data/doc/css/common.css +0 -68
  63. data/lib/parser/lexer.rl +0 -2383
  64. data/lib/parser/macruby.y +0 -2198
  65. data/lib/parser/ruby18.y +0 -1934
  66. data/lib/parser/ruby19.y +0 -2175
  67. data/lib/parser/ruby20.y +0 -2353
  68. data/lib/parser/ruby21.y +0 -2357
  69. data/lib/parser/ruby22.y +0 -2364
  70. data/lib/parser/ruby23.y +0 -2370
  71. data/lib/parser/ruby24.y +0 -2408
  72. data/lib/parser/ruby25.y +0 -2405
  73. data/lib/parser/ruby26.y +0 -2413
  74. data/lib/parser/rubymotion.y +0 -2182
  75. data/test/bug_163/fixtures/input.rb +0 -5
  76. data/test/bug_163/fixtures/output.rb +0 -5
  77. data/test/bug_163/rewriter.rb +0 -20
  78. data/test/helper.rb +0 -52
  79. data/test/parse_helper.rb +0 -315
  80. data/test/racc_coverage_helper.rb +0 -133
  81. data/test/test_base.rb +0 -31
  82. data/test/test_current.rb +0 -27
  83. data/test/test_diagnostic.rb +0 -96
  84. data/test/test_diagnostic_engine.rb +0 -62
  85. data/test/test_encoding.rb +0 -99
  86. data/test/test_lexer.rb +0 -3543
  87. data/test/test_lexer_stack_state.rb +0 -78
  88. data/test/test_parse_helper.rb +0 -80
  89. data/test/test_parser.rb +0 -7087
  90. data/test/test_runner_rewrite.rb +0 -47
  91. data/test/test_source_buffer.rb +0 -162
  92. data/test/test_source_comment.rb +0 -36
  93. data/test/test_source_comment_associator.rb +0 -367
  94. data/test/test_source_map.rb +0 -15
  95. data/test/test_source_range.rb +0 -172
  96. data/test/test_source_rewriter.rb +0 -541
  97. data/test/test_source_rewriter_action.rb +0 -46
  98. data/test/test_source_tree_rewriter.rb +0 -173
  99. data/test/test_static_environment.rb +0 -45
  100. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  101. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  102. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+
5
+ # Holds p->max_numparam from parse.y
6
+ #
7
+ # @api private
8
+ class MaxNumparamStack
9
+ attr_reader :stack
10
+
11
+ ORDINARY_PARAMS = -1
12
+
13
+ def initialize
14
+ @stack = []
15
+ end
16
+
17
+ def empty?
18
+ @stack.size == 0
19
+ end
20
+
21
+ def has_ordinary_params!
22
+ set(ORDINARY_PARAMS)
23
+ end
24
+
25
+ def has_ordinary_params?
26
+ top == ORDINARY_PARAMS
27
+ end
28
+
29
+ def has_numparams?
30
+ top && top > 0
31
+ end
32
+
33
+ def register(numparam)
34
+ set( [top, numparam].max )
35
+ end
36
+
37
+ def top
38
+ @stack.last[:value]
39
+ end
40
+
41
+ def push(static:)
42
+ @stack.push(value: 0, static: static)
43
+ end
44
+
45
+ def pop
46
+ @stack.pop[:value]
47
+ end
48
+
49
+ private
50
+
51
+ def set(value)
52
+ @stack.last[:value] = value
53
+ end
54
+ end
55
+
56
+ end
@@ -10,60 +10,79 @@ module Parser
10
10
  #
11
11
  MESSAGES = {
12
12
  # Lexer errors
13
- :unicode_point_too_large => 'invalid Unicode codepoint (too large)',
14
- :invalid_escape => 'invalid escape character syntax',
15
- :incomplete_escape => 'incomplete character syntax',
16
- :invalid_hex_escape => 'invalid hex escape',
17
- :invalid_unicode_escape => 'invalid Unicode escape',
18
- :unterminated_unicode => 'unterminated Unicode escape',
19
- :escape_eof => 'escape sequence meets end of file',
20
- :string_eof => 'unterminated string meets end of file',
21
- :regexp_options => 'unknown regexp options: %{options}',
22
- :cvar_name => "`%{name}' is not allowed as a class variable name",
23
- :ivar_name => "`%{name}' is not allowed as an instance variable name",
24
- :trailing_in_number => "trailing `%{character}' in number",
25
- :empty_numeric => 'numeric literal without digits',
26
- :invalid_octal => 'invalid octal digit',
27
- :no_dot_digit_literal => 'no .<digit> floating literal anymore; put 0 before dot',
28
- :bare_backslash => 'bare backslash only allowed before newline',
29
- :unexpected => "unexpected `%{character}'",
30
- :embedded_document => 'embedded document meets end of file (and they embark on a romantic journey)',
31
- :heredoc_id_has_newline => 'here document identifier across newlines, never match',
32
- :heredoc_id_ends_with_nl => 'here document identifier ends with a newline',
13
+ :unicode_point_too_large => 'invalid Unicode codepoint (too large)',
14
+ :invalid_escape => 'invalid escape character syntax',
15
+ :incomplete_escape => 'incomplete character syntax',
16
+ :invalid_hex_escape => 'invalid hex escape',
17
+ :invalid_unicode_escape => 'invalid Unicode escape',
18
+ :unterminated_unicode => 'unterminated Unicode escape',
19
+ :escape_eof => 'escape sequence meets end of file',
20
+ :string_eof => 'unterminated string meets end of file',
21
+ :regexp_options => 'unknown regexp options: %{options}',
22
+ :cvar_name => "`%{name}' is not allowed as a class variable name",
23
+ :ivar_name => "`%{name}' is not allowed as an instance variable name",
24
+ :trailing_in_number => "trailing `%{character}' in number",
25
+ :empty_numeric => 'numeric literal without digits',
26
+ :invalid_octal => 'invalid octal digit',
27
+ :no_dot_digit_literal => 'no .<digit> floating literal anymore; put 0 before dot',
28
+ :bare_backslash => 'bare backslash only allowed before newline',
29
+ :unexpected => "unexpected `%{character}'",
30
+ :embedded_document => 'embedded document meets end of file (and they embark on a romantic journey)',
31
+ :heredoc_id_has_newline => 'here document identifier across newlines, never match',
32
+ :heredoc_id_ends_with_nl => 'here document identifier ends with a newline',
33
+ :unterminated_heredoc_id => 'unterminated heredoc id',
33
34
 
34
35
  # Lexer warnings
35
36
  :invalid_escape_use => 'invalid character syntax; use ?%{escape}',
36
37
  :ambiguous_literal => 'ambiguous first argument; put parentheses or a space even after the operator',
38
+ :ambiguous_regexp => "ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after `/' operator",
37
39
  :ambiguous_prefix => "`%{prefix}' interpreted as argument prefix",
40
+ :triple_dot_at_eol => '... at EOL, should be parenthesized',
38
41
 
39
42
  # Parser errors
40
- :nth_ref_alias => 'cannot define an alias for a back-reference variable',
41
- :begin_in_method => 'BEGIN in method',
42
- :backref_assignment => 'cannot assign to a back-reference variable',
43
- :invalid_assignment => 'cannot assign to a keyword',
44
- :module_name_const => 'class or module name must be a constant literal',
45
- :unexpected_token => 'unexpected token %{token}',
46
- :argument_const => 'formal argument cannot be a constant',
47
- :argument_ivar => 'formal argument cannot be an instance variable',
48
- :argument_gvar => 'formal argument cannot be a global variable',
49
- :argument_cvar => 'formal argument cannot be a class variable',
50
- :duplicate_argument => 'duplicate argument name',
51
- :empty_symbol => 'empty symbol literal',
52
- :odd_hash => 'odd number of entries for a hash',
53
- :singleton_literal => 'cannot define a singleton method for a literal',
54
- :dynamic_const => 'dynamic constant assignment',
55
- :const_reassignment => 'constant re-assignment',
56
- :module_in_def => 'module definition in method body',
57
- :class_in_def => 'class definition in method body',
58
- :unexpected_percent_str => '%{type}: unknown type of percent-literal',
59
- :block_and_blockarg => 'both block argument and literal block are passed',
60
- :masgn_as_condition => 'multiple assignment in conditional context',
61
- :block_given_to_yield => 'block given to yield',
62
- :invalid_regexp => '%{message}',
63
- :invalid_return => 'Invalid return in class/module body',
43
+ :nth_ref_alias => 'cannot define an alias for a back-reference variable',
44
+ :begin_in_method => 'BEGIN in method',
45
+ :backref_assignment => 'cannot assign to a back-reference variable',
46
+ :invalid_assignment => 'cannot assign to a keyword',
47
+ :module_name_const => 'class or module name must be a constant literal',
48
+ :unexpected_token => 'unexpected token %{token}',
49
+ :argument_const => 'formal argument cannot be a constant',
50
+ :argument_ivar => 'formal argument cannot be an instance variable',
51
+ :argument_gvar => 'formal argument cannot be a global variable',
52
+ :argument_cvar => 'formal argument cannot be a class variable',
53
+ :duplicate_argument => 'duplicate argument name',
54
+ :empty_symbol => 'empty symbol literal',
55
+ :odd_hash => 'odd number of entries for a hash',
56
+ :singleton_literal => 'cannot define a singleton method for a literal',
57
+ :dynamic_const => 'dynamic constant assignment',
58
+ :const_reassignment => 'constant re-assignment',
59
+ :module_in_def => 'module definition in method body',
60
+ :class_in_def => 'class definition in method body',
61
+ :unexpected_percent_str => '%{type}: unknown type of percent-literal',
62
+ :block_and_blockarg => 'both block argument and literal block are passed',
63
+ :masgn_as_condition => 'multiple assignment in conditional context',
64
+ :block_given_to_yield => 'block given to yield',
65
+ :invalid_regexp => '%{message}',
66
+ :invalid_return => 'Invalid return in class/module body',
67
+ :csend_in_lhs_of_masgn => '&. inside multiple assignment destination',
68
+ :cant_assign_to_numparam => 'cannot assign to numbered parameter %{name}',
69
+ :reserved_for_numparam => '%{name} is reserved for numbered parameter',
70
+ :ordinary_param_defined => 'ordinary parameter is defined',
71
+ :numparam_used_in_outer_scope => 'numbered parameter is already used in an outer scope',
72
+ :circular_argument_reference => 'circular argument reference %{var_name}',
73
+ :pm_interp_in_var_name => 'symbol literal with interpolation is not allowed',
74
+ :lvar_name => "`%{name}' is not allowed as a local variable name",
75
+ :undefined_lvar => "no such local variable: `%{name}'",
76
+ :duplicate_variable_name => 'duplicate variable name %{name}',
77
+ :duplicate_pattern_key => 'duplicate hash pattern key %{name}',
78
+ :endless_setter => 'setter method cannot be defined in an endless method definition',
79
+ :invalid_id_to_get => 'identifier %{identifier} is not valid to get',
80
+ :forward_arg_after_restarg => '... after rest argument',
81
+ :no_anonymous_blockarg => 'no anonymous block parameter',
64
82
 
65
83
  # Parser warnings
66
84
  :useless_else => 'else without rescue is useless',
85
+ :duplicate_hash_key => 'key is duplicated and overwritten',
67
86
 
68
87
  # Parser errors that are not Ruby errors
69
88
  :invalid_encoding => 'literal contains escape sequences incompatible with UTF-8',
@@ -81,4 +100,19 @@ module Parser
81
100
  :crossing_insertions => 'the rewriting action on:',
82
101
  :crossing_insertions_conflict => 'is crossing that on:',
83
102
  }.freeze
103
+
104
+ # @api private
105
+ module Messages
106
+ # Formats the message, returns a raw template if there's nothing to interpolate
107
+ #
108
+ # Code like `format("", {})` gives a warning, and so this method tries interpolating
109
+ # only if `arguments` hash is not empty.
110
+ #
111
+ # @api private
112
+ def self.compile(reason, arguments)
113
+ template = MESSAGES[reason]
114
+ return template if Hash === arguments && arguments.empty?
115
+ format(template, arguments)
116
+ end
117
+ end
84
118
  end
data/lib/parser/meta.rb CHANGED
@@ -7,7 +7,7 @@ module Parser
7
7
  # All node types that parser can produce. Not all parser versions
8
8
  # will be able to produce every possible node.
9
9
  NODE_TYPES =
10
- %w(
10
+ %i(
11
11
  true false nil int float str dstr
12
12
  sym dsym xstr regopt regexp array splat
13
13
  pair kwsplat hash irange erange self
@@ -18,12 +18,22 @@ module Parser
18
18
  match_with_lvasgn match_current_line
19
19
  module class sclass def defs undef alias args
20
20
  cbase arg optarg restarg blockarg block_pass kwarg kwoptarg
21
- kwrestarg send csend super zsuper yield block
21
+ kwrestarg kwnilarg send csend super zsuper yield block
22
22
  and not or if when case while until while_post
23
23
  until_post for break next redo return resbody
24
24
  kwbegin begin retry preexe postexe iflipflop eflipflop
25
25
  shadowarg complex rational __FILE__ __LINE__ __ENCODING__
26
- ).map(&:to_sym).to_set.freeze
26
+ ident lambda indexasgn index procarg0
27
+ restarg_expr blockarg_expr
28
+ objc_kwarg objc_restarg objc_varargs
29
+ numargs numblock forward_args forwarded_args forward_arg
30
+ case_match in_match in_pattern
31
+ match_var pin match_alt match_as match_rest
32
+ array_pattern match_with_trailing_comma array_pattern_with_tail
33
+ hash_pattern const_pattern if_guard unless_guard match_nil_pattern
34
+ empty_else find_pattern kwargs
35
+ match_pattern_p match_pattern
36
+ ).to_set.freeze
27
37
 
28
38
  end # Meta
29
39
  end # Parser