Class: Parser::Builders::Default
- Inherits:
-
Object
- Object
- Parser::Builders::Default
- Defined in:
- lib/parser/builders/default.rb
Overview
Default AST builder. Uses AST::Nodes.
Class Attribute Summary collapse
-
.emit_arg_inside_procarg0 ⇒ Boolean
AST compatibility attribute; causes a single non-mlhs block argument to be wrapped in s(:procarg0).
-
.emit_encoding ⇒ Boolean
AST compatibility attribute; locations of ‘__ENCODING__` are not the same as locations of `Encoding::UTF_8` causing problems during rewriting, all new code should set this attribute to true.
-
.emit_forward_arg ⇒ Boolean
AST compatibility attribute; arguments forwarding initially didn’t have support for leading arguments (i.e. ‘def m(a, …); end` was a syntax error).
-
.emit_index ⇒ Boolean
AST compatibility attribute; indexed assignment, ‘x[] = 1`, is not semantically equivalent to calling the method directly, `x.[]=(1)`.
-
.emit_lambda ⇒ Boolean
AST compatibility attribute; since ‘-> {}` is not semantically equivalent to `lambda {}`, all new code should set this attribute to true.
-
.emit_procarg0 ⇒ Boolean
AST compatibility attribute; block arguments of ‘m { |a| }` are not semantically equivalent to block arguments of `m { |a,| }` or `m { |a, b| }`, all new code should set this attribute to true.
Instance Attribute Summary collapse
-
#emit_file_line_as_literals ⇒ Boolean
If set to true (the default), ‘__FILE__` and `__LINE__` are transformed to literal nodes.
- #parser ⇒ Object private
Class Method Summary collapse
- .modernize ⇒ Object private
Instance Method Summary collapse
-
#initialize ⇒ Default
constructor
Initializes attributes:.
Constructor Details
#initialize ⇒ Default
Initializes attributes:
* `emit_file_line_as_literals`: `true`
164 165 166 |
# File 'lib/parser/builders/default.rb', line 164 def initialize @emit_file_line_as_literals = true end |
Class Attribute Details
.emit_arg_inside_procarg0 ⇒ Boolean
AST compatibility attribute; causes a single non-mlhs block argument to be wrapped in s(:procarg0).
If set to false (the default), block arguments ‘|a|` are emitted as `s(:args, s(:procarg0, :a))`
If set to true, block arguments ‘|a|` are emitted as `s(:args, s(:procarg0, s(:arg, :a))`
97 98 99 |
# File 'lib/parser/builders/default.rb', line 97 def emit_arg_inside_procarg0 @emit_arg_inside_procarg0 end |
.emit_encoding ⇒ Boolean
AST compatibility attribute; locations of ‘__ENCODING__` are not the same as locations of `Encoding::UTF_8` causing problems during rewriting, all new code should set this attribute to true.
If set to false (the default), ‘__ENCODING__` is emitted as ` s(:const, s(:const, nil, :Encoding), :UTF_8)`.
If set to true, ‘__ENCODING__` is emitted as `s(:__ENCODING__)`.
58 59 60 |
# File 'lib/parser/builders/default.rb', line 58 def emit_encoding @emit_encoding end |
.emit_forward_arg ⇒ Boolean
AST compatibility attribute; arguments forwarding initially didn’t have support for leading arguments (i.e. ‘def m(a, …); end` was a syntax error). However, Ruby 3.0 added support for any number of arguments in front of the `…`.
If set to false (the default):
1. `def m(...) end` is emitted as
s(:def, :m, s(:forward_args), nil)
2. `def m(a, b, ...) end` is emitted as
s(:def, :m,
s(:args, s(:arg, :a), s(:arg, :b), s(:forward_arg)))
If set to true it uses a single format:
1. `def m(...) end` is emitted as
s(:def, :m, s(:args, s(:forward_arg)))
2. `def m(a, b, ...) end` is emitted as
s(:def, :m, s(:args, s(:arg, :a), s(:arg, :b), s(:forward_arg)))
It does’t matter that much on 2.7 (because there can’t be any leading arguments), but on 3.0 it should be better enabled to use a single AST format.
126 127 128 |
# File 'lib/parser/builders/default.rb', line 126 def emit_forward_arg @emit_forward_arg end |
.emit_index ⇒ Boolean
AST compatibility attribute; indexed assignment, ‘x[] = 1`, is not semantically equivalent to calling the method directly, `x.[]=(1)`. Specifically, in the former case, the expression’s value is always 1, and in the latter case, the expression’s value is the return value of the ‘[]=` method.
If set to false (the default), ‘self` is emitted as `s(:send, s(:self), :[], s(:int, 1))`, and `self = 2` is emitted as `s(:send, s(:self), :[]=, s(:int, 1), s(:int, 2))`.
If set to true, ‘self` is emitted as `s(:index, s(:self), s(:int, 1))`, and `self = 2` is emitted as `s(:indexasgn, s(:self), s(:int, 1), s(:int, 2))`.
80 81 82 |
# File 'lib/parser/builders/default.rb', line 80 def emit_index @emit_index end |
.emit_lambda ⇒ Boolean
AST compatibility attribute; since ‘-> {}` is not semantically equivalent to `lambda {}`, all new code should set this attribute to true.
If set to false (the default), ‘-> {}` is emitted as `s(:block, s(:send, nil, :lambda), s(:args), nil)`.
If set to true, ‘-> {}` is emitted as `s(:block, s(:lambda), s(:args), nil)`.
22 23 24 |
# File 'lib/parser/builders/default.rb', line 22 def emit_lambda @emit_lambda end |
.emit_procarg0 ⇒ Boolean
AST compatibility attribute; block arguments of ‘m { |a| }` are not semantically equivalent to block arguments of `m { |a,| }` or `m { |a, b| }`, all new code should set this attribute to true.
If set to false (the default), arguments of ‘m { |a| }` are emitted as `s(:args, s(:arg, :a))`.
If set to true, arguments of ‘m { |a| }` are emitted as `s(:args, s(:procarg0, :a)).
40 41 42 |
# File 'lib/parser/builders/default.rb', line 40 def emit_procarg0 @emit_procarg0 end |
Instance Attribute Details
#emit_file_line_as_literals ⇒ Boolean
If set to true (the default), ‘__FILE__` and `__LINE__` are transformed to literal nodes. For example, `s(:str, “lib/foo.rb”)` and `s(:int, 10)`.
If set to false, ‘__FILE__` and `__LINE__` are emitted as-is, i.e. as `s(:__FILE__)` and `s(:__LINE__)` nodes.
Source maps are identical in both cases.
158 159 160 |
# File 'lib/parser/builders/default.rb', line 158 def emit_file_line_as_literals @emit_file_line_as_literals end |
#parser ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 |
# File 'lib/parser/builders/default.rb', line 146 def parser @parser end |
Class Method Details
.modernize ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
134 135 136 137 138 139 140 141 |
# File 'lib/parser/builders/default.rb', line 134 def modernize @emit_lambda = true @emit_procarg0 = true @emit_encoding = true @emit_index = true @emit_arg_inside_procarg0 = true @emit_forward_arg = true end |