parser 2.6.0.0 → 2.7.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +11 -11
  4. data/CHANGELOG.md +88 -0
  5. data/README.md +7 -0
  6. data/Rakefile +1 -0
  7. data/doc/AST_FORMAT.md +410 -3
  8. data/lib/parser/all.rb +1 -0
  9. data/lib/parser/ast/processor.rb +39 -1
  10. data/lib/parser/base.rb +23 -1
  11. data/lib/parser/builders/default.rb +312 -15
  12. data/lib/parser/context.rb +12 -0
  13. data/lib/parser/current.rb +15 -6
  14. data/lib/parser/current_arg_stack.rb +43 -0
  15. data/lib/parser/lexer/dedenter.rb +48 -49
  16. data/lib/parser/lexer.rb +11934 -11278
  17. data/lib/parser/lexer.rl +207 -58
  18. data/lib/parser/macruby.rb +1509 -1507
  19. data/lib/parser/macruby.y +1 -1
  20. data/lib/parser/max_numparam_stack.rb +48 -0
  21. data/lib/parser/messages.rb +55 -44
  22. data/lib/parser/meta.rb +9 -1
  23. data/lib/parser/ruby18.rb +1255 -1248
  24. data/lib/parser/ruby18.y +1 -1
  25. data/lib/parser/ruby19.rb +1645 -1638
  26. data/lib/parser/ruby19.y +1 -1
  27. data/lib/parser/ruby20.rb +1766 -1767
  28. data/lib/parser/ruby20.y +1 -1
  29. data/lib/parser/ruby21.rb +1654 -1656
  30. data/lib/parser/ruby21.y +1 -1
  31. data/lib/parser/ruby22.rb +1772 -1767
  32. data/lib/parser/ruby22.y +1 -1
  33. data/lib/parser/ruby23.rb +1088 -1092
  34. data/lib/parser/ruby23.y +1 -1
  35. data/lib/parser/ruby24.rb +1837 -1843
  36. data/lib/parser/ruby24.y +1 -1
  37. data/lib/parser/ruby25.rb +1750 -1755
  38. data/lib/parser/ruby25.y +2 -2
  39. data/lib/parser/ruby26.rb +1748 -1752
  40. data/lib/parser/ruby26.y +2 -2
  41. data/lib/parser/ruby27.rb +7749 -0
  42. data/lib/parser/ruby27.y +2923 -0
  43. data/lib/parser/rubymotion.rb +1492 -1497
  44. data/lib/parser/rubymotion.y +1 -1
  45. data/lib/parser/runner/ruby_parse.rb +2 -2
  46. data/lib/parser/runner.rb +5 -0
  47. data/lib/parser/source/tree_rewriter.rb +2 -2
  48. data/lib/parser/static_environment.rb +10 -0
  49. data/lib/parser/tree_rewriter.rb +2 -1
  50. data/lib/parser/variables_stack.rb +32 -0
  51. data/lib/parser/version.rb +1 -1
  52. data/lib/parser.rb +3 -0
  53. data/parser.gemspec +3 -2
  54. data/test/helper.rb +8 -0
  55. data/test/parse_helper.rb +2 -1
  56. data/test/test_current.rb +2 -0
  57. data/test/test_lexer.rb +72 -7
  58. data/test/test_parser.rb +2218 -8
  59. data/test/test_runner_parse.rb +35 -0
  60. metadata +20 -8
data/lib/parser/macruby.y CHANGED
@@ -81,7 +81,7 @@ rule
81
81
  else_t, else_ = val[2]
82
82
  ensure_t, ensure_ = val[3]
83
83
 
84
- if rescue_bodies.empty? && !else_.nil?
84
+ if rescue_bodies.empty? && !else_t.nil?
85
85
  diagnostic :warning, :useless_else, nil, else_t
86
86
  end
87
87
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parser
4
+
5
+ class MaxNumparamStack
6
+ attr_reader :stack
7
+
8
+ def initialize
9
+ @stack = []
10
+ end
11
+
12
+ def has_ordinary_params!
13
+ set(-1)
14
+ end
15
+
16
+ def has_ordinary_params?
17
+ top < 0
18
+ end
19
+
20
+ def has_numparams?
21
+ top > 0
22
+ end
23
+
24
+ def register(numparam)
25
+ set( [top, numparam].max )
26
+ end
27
+
28
+ def top
29
+ @stack.last
30
+ end
31
+
32
+ def push
33
+ @stack.push(0)
34
+ end
35
+
36
+ def pop
37
+ @stack.pop
38
+ end
39
+
40
+ private
41
+
42
+ def set(value)
43
+ @stack.pop
44
+ @stack.push(value)
45
+ end
46
+ end
47
+
48
+ end
@@ -10,57 +10,68 @@ 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',
37
38
  :ambiguous_prefix => "`%{prefix}' interpreted as argument prefix",
39
+ :triple_dot_at_eol => '... at EOL, should be parenthesized',
38
40
 
39
41
  # 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',
42
+ :nth_ref_alias => 'cannot define an alias for a back-reference variable',
43
+ :begin_in_method => 'BEGIN in method',
44
+ :backref_assignment => 'cannot assign to a back-reference variable',
45
+ :invalid_assignment => 'cannot assign to a keyword',
46
+ :module_name_const => 'class or module name must be a constant literal',
47
+ :unexpected_token => 'unexpected token %{token}',
48
+ :argument_const => 'formal argument cannot be a constant',
49
+ :argument_ivar => 'formal argument cannot be an instance variable',
50
+ :argument_gvar => 'formal argument cannot be a global variable',
51
+ :argument_cvar => 'formal argument cannot be a class variable',
52
+ :duplicate_argument => 'duplicate argument name',
53
+ :empty_symbol => 'empty symbol literal',
54
+ :odd_hash => 'odd number of entries for a hash',
55
+ :singleton_literal => 'cannot define a singleton method for a literal',
56
+ :dynamic_const => 'dynamic constant assignment',
57
+ :const_reassignment => 'constant re-assignment',
58
+ :module_in_def => 'module definition in method body',
59
+ :class_in_def => 'class definition in method body',
60
+ :unexpected_percent_str => '%{type}: unknown type of percent-literal',
61
+ :block_and_blockarg => 'both block argument and literal block are passed',
62
+ :masgn_as_condition => 'multiple assignment in conditional context',
63
+ :block_given_to_yield => 'block given to yield',
64
+ :invalid_regexp => '%{message}',
65
+ :invalid_return => 'Invalid return in class/module body',
66
+ :csend_in_lhs_of_masgn => '&. inside multiple assignment destination',
67
+ :cant_assign_to_numparam => 'cannot assign to numbered parameter %{name}',
68
+ :ordinary_param_defined => 'ordinary parameter is defined',
69
+ :numparam_used_in_outer_scope => 'numbered parameter is already used in an outer scope',
70
+ :circular_argument_reference => 'circular argument reference %{var_name}',
71
+ :pm_interp_in_var_name => 'symbol literal with interpolation is not allowed',
72
+ :lvar_name => "`%{name}' is not allowed as a local variable name",
73
+ :duplicate_variable_name => 'duplicate variable name %{name}',
74
+ :duplicate_pattern_key => 'duplicate hash pattern key %{name}',
64
75
 
65
76
  # Parser warnings
66
77
  :useless_else => 'else without rescue is useless',
data/lib/parser/meta.rb CHANGED
@@ -18,11 +18,19 @@ 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
+ ident root lambda indexasgn index procarg0
27
+ restarg_expr blockarg_expr
28
+ objc_kwarg objc_restarg objc_varargs
29
+ numargs numblock forward_args forwarded_args
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
26
34
  ).map(&:to_sym).to_set.freeze
27
35
 
28
36
  end # Meta