* parse.y (heredoc_dedent): manage the last node of NODE_ARRAY,
when concatenating dedented literals.
[ruby-core:89649] [Bug #15272]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (command): set the last location from the location
managed by bison, so that other nodes are not needed.
[ruby-core:89648] [Bug #15271]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
You can now write the following without warning.
user = User.all.find {|user| cond(user) }
Fixes [Feature #12490].
A patch from Soutaro Matsumoto <matsumoto@soutaro.com>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
You can now write the following without warning.
user = User.all.find {|user| cond(user) }
Fixes [Feature #12490].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to start with the argument.
e.g. The locations of the NODE_SCOPE is fixed:
```
-> x { 1 + 2 }
```
* Before
```
NODE_SCOPE (line: 1, location: (1,2)-(1,14))
```
* After
```
NODE_SCOPE (line: 1, location: (1,3)-(1,14))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* node.h: Add `nd_first_loc` and `nd_set_first_loc`
* parse.y: Fix to start with the beginning of `->` .
e.g. The locations of the NODE_LAMBDA is fixed:
```
-> x { 1 + 2 }
```
* Before
```
NODE_LAMBDA (line: 1, location: (1,2)-(1,14))
```
* After
```
NODE_LAMBDA (line: 1, location: (1,0)-(1,14))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (arg_blk_pass): preceeding arguments node may be NULL when
an empty keyword argument hash splat is optimized away.
[ruby-core:88890] [Bug #15087]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because of the lack of this case, `[*ary,1,2,3,4,5,6]` was parsed into
an inefficient AST like `ary + [1,2] + [3,4] + [5,6]`.
A patch from Anmol Chopra <anmolchopra@rocketbox.in>.
Fixes [Bug #15018].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The code fragments that initializes coverage data were scattered into
both parse.y and compile.c. parse.y allocated a coverage data, and
compile.c initialize the data.
To remove this cross-cutting concern, this change moves the allocation
from "coverage" function of parse.y to "rb_iseq_new_top" of iseq.c.
For the sake, parse.y just counts the line number of the original source
code, and the number is passed via rb_ast_body_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Now endless range can be created by either a literal `(1..)` or explicit
range creation `Range.new(1, nil)`. [Bug #14845]
This change is intended for "early failure"; for example,
`(1..var).to_a` causes out of memory if `var` is inadvertently nil.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
When an empty rule or a mid-rule action is reduced,
`YYLLOC_DEFAULT` is called with the third parameter to be zero.
If we use `RUBY_SET_YYLLOC_OF_NONE` to set their locations,
sometimes the end position of NODE indicates a blank.
For example, `a.b ;` generates `NODE_CALL (line: 1, location: (1,0)-(1,4))*`,
whose end position indicates a blank.
This is because of the following reasons:
* `NODE_CALL` is created when `primary_value call_op operation2 opt_paren_args` is
reduced to `method_call`.
* `opt_paren_args` is `none`.
* `yylex` is called and `lex.pbeg` moves before `none` is reduced, so
the beginning position of `none` does not match with the end position of `operation2`.
To fix locations, use `YYRHSLOC(Rhs, 0)` in `YYLLOC_DEFAULT`
(0 "refers to the symbol just before the reduction").
By this change, the bottom of the location stack would be referenced,
so initialize the bottom with `RUBY_SET_YYLLOC_OF_NONE` in `%initial-action`.
Ref: https://www.gnu.org/software/bison/manual/html_node/Location-Default-Action.html#Location-Default-Action
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (new_bodystmt): Fix locations of NODE_RESCUE
to end with nd_else or nd_resq. Before this commit,
locations of NODE_RESCUE included locations of nd_ensr
of NODE_ENSURE which is a parent node of NODE_RESCUE.
e.g. The location of the end of NODE_RESCUE is fixed:
```
def a
:b
rescue
:c
ensure
:d
end
```
* Before
```
NODE_RESCUE (line: 2, location: (2,2)-(6,4))
```
* After
```
NODE_RESCUE (line: 3, location: (2,2)-(5,0))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Another part of the plan to reduce dependencies on malloc_usable_size
which costs us speed: https://bugs.ruby-lang.org/issues/10238
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
No automatic type promotion is expected for variadic arguments.
You have to do it by hand.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (cond0): do not warn literal boolean (true and false) in
condition expressions, as they are often used as infinite loops,
deactivated code block, etc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (primary, new_args_tail, local_tbl): keep the order;
allocate an empty imemo first then xmalloc, to get rid of
potential memory leak when allocation imemo failed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to start with the end of dots.
e.g. The locations of the NODE_NIL is fixed:
```
1..
```
* Before
```
NODE_NIL (line: 1, location: (1,0)-(1,3))
```
* After
```
NODE_NIL (line: 1, location: (1,3)-(1,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* gc.c (rb_alloc_tmp_buffer_with_count): keep the order; allocate
an empty imemo first then xmalloc, to get rid of potential
memory leak when allocation imemo failed.
* parse.y (rb_parser_malloc, rb_parser_calloc, rb_parser_realloc):
ditto.
* process.c (rb_execarg_allocate_dup2_tmpbuf): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
imemo_alloc is used for three purposes: auto-free pointer (alternative
of alloca), alloc_tmp_buffer, and heap allocation for bison.
To make it clear, this change introduces three functions:
rb_imemo_alloc_auto_free_pointer,
rb_imemo_alloc_auto_free_maybe_mark_buffer, and
rb_imemo_alloc_parser_heap.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_imemo_alloc_new returns rb_imemo_alloc_t*, but took VALUEs, which is
inconsistent. To make the intention clear, it now takes only a pointer
to the buffer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Typical usages:
```
p ary[1..] # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_dedent_string): stated that Ripper.dedent_string
is for internal use only.
[ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (no_digits): return tINTEGER instead of unexpected
end-of-input, to get rid of extra error messages.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: [DOC] fix return type in call-seq of Ripper.dedent_string,
clarify the method's behavior.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (bodystmt): expand opt_else to show the error message at
the right place.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (here_document): a continuing line is not the
terminator. [ruby-core:86283] [Bug #14621]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (tokadd_string): stop at continued line in dedented here
documents, to dedent for each lines before removing escaped
newlines. [ruby-core:86236] [Bug #14621]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (yycompile): in some cases (warning, error, dtrace,...),
ruby_sourcefile is expected to be NUL-terminated, so ensure it.
* template/prelude.c.tmpl (prelude_name): NUL-terminate to get rid
of copying static data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (k_rescue, k_ensure): ignore indentations of `do`, it
is not at the beginning of line usually.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (f_kwrest): add the variable name as an argument, as
well as an internal variable.
* parse.y (new_args_tail): now keyword rest argument variable is
always placed between keyword arguments and block argument, so
so just reorder required and optional keyword arguments. no
longer kwrest duplicates.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: use tSP same as ripper instead of tSPACE.
[ruby-core:86080] [Bug #14597]
* ext/ripper/eventids2.c: tSP is defined in ripper.c now.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (heredoc_dedent): fix interpolated string literal dedent,
remove indentations from only nodes with the newline flag.
[ruby-core:85983] [Bug #14584]
* parse.y (here_document): set the newline flag on literal string
nodes starting at the beginning of line.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (tSPACE): define a separate token for escaped space, to
fix `redefining user token number of ' '` error at word list
separator on bison 2.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: named escaped whitespaces to show unexpected character.
bare whitespaces should not appear outside of word_list.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (assign_in_cond): refine a warning message for
assignment of a literal in conditinal expression.
[ruby-core:85872] [Bug #14562]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yylex): as well as `tLBRACE_ARG` (expr block),
`tLBRACE` (primary block) also does not accept a label. only
hash brace accepts a label.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Currently, parser.y includes core parser and Ripper parser obscurity.
In addition, *some* Ripper code uses the result of the core parser,
which make it difficult to separate the two parsers.
I want to simplify this, not by separating the two parsers, but by
making *all* Ripper actions follows the core parser actions.
In other words, all the core parser actions run always even in Ripper,
and after that, Ripper-specific actions run.
For tha sake, in principle, I want to put `/*% ripper: ... %*/` in the
end of actions.
Anyway, it is too dirty to put it within expressions, IMO.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I thought this trick was needed because the result of var_field was
passed to different arguments, as follows:
```
$1 = var_field(p, $1);
$$ = backref_assign_error(p, $1, $1, &@$);
```
Currently the DSL supports that one result is passed to one argument.
However, after the refactoring, I found that `backref_assign_error`
uses only one `$1`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (dot_or_colon): made type of `dot_or_colon` and EXPR_DOT
tokens to <id> and set those IDs at tokenization. type cast at
primary in ripper is no longer needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (block_param): embed excessed_comma event result in
place of rest argument, instead of dispatching with the whole
parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`foo!(...)` means Ripper event, and `foo(...)` means C function/macro
call. This is for fail-safe; if I forget `!` accidentally, it would
fail to compile, instead of wrongly adding a new Ripper event.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (command): assign to $$. should not rely upon
undocumented behavior.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Instead of `_foo`. This makes it useful to do word boundary search of
the editor.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Currently, parse.y actions are hard to read and write because the code
has double meaning (for core parser and for ripper). I think that, if
it is easy to write ripper's code shortly and simply, the double meaning
trick is not needed.
For the sake, this change adds a simple DSL for ripper's code. For
example, in parse.y, we can write:
/*% ripper: stmts_add(stmts_new, void_stmt) %*/
instead of:
$$ = dispatch2(stmts_add, dispatch0(stmts_new),
dispatch0(void_stmt));
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (assignable): no longer needs to undef since r61899.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (REQUIRED_KEYWORD): special argument for required
keyword argument, for core and ripper.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NODE_FOR was used both for "for"-statement itself and for
multi-assignment of for-statement (for x, y, in...end).
This change separates the two purposes, NODE_FOR for the former, and
newly introduced NODE_FOR_MASGN for the latter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (tokadd_mbchar): renamed and expand callers with p.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Mixing other encoding string literals in one Regexp caused SEGV.
This bug was found by CoverityScan.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
There were four cases that uses new_command_qcall and then
method_add_block. This change factors out the four rules.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Nowadays, there are less rules whose return value is NULL.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
There are many usages assuming that bodystmt always returns non-null.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The code fragments were commented out in YARV merge era.
I believe that it will be never needed in near future.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (yydebug): define to disable a global variable and get
rid of linker error when static linked ext.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I don't know what it was, but seems that it has been already fixed since
r12117.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The current parse.y won't compile with yacc since it depends on many
bison's extensions. Also, configure.ac does not have a check for yacc,
so the macro OLD_YACC is no longer used.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
In parse.y many functions were suffixed "_gen" and had companion macros
to pass struct parser_params implicitly, which made parse.c bigger and
more obscure.
This change expands and removes almost all "*_gen" macros. This
requires explicit passing of struct parser_params, i.e., we need to
write "foo(p, ..)" instead of "foo(..)". However, it is just extra
three letters. I believe that this is easier to understand.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
For example, `lex_strterm` is expanded to `p->lex.strterm`.
I believe that this expansion make the code straightforward.
They look not so annoying because "parser" was renamed to "p".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because I want to use the name "p" for struct parser_params through
parse.c. This change renames "p" to "ptr", "paren", etc. depending upon
the context.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because the part of the code is already within `#ifndef RIPPER`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* remove unused argument len
* factor out initialization code of token_info
* make the condition of "mismatched indentations" warning easy to understand
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
cmdarg_stack became inconsistent state due to look-ahead, and LEXPOP
hack smoothed over the inconsistency.
This commit fixes the inconsisitent state itself, and removes LEXPOP
hack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change partially reverts r61724 and take another approach:
exploiting struct local_vars to backup the cond_stack state.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (primary): save/restore COND and CMDARG stacks at method
definition, to distinguish do_block and do_cond properly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because the name "code_range" is ambiguous with encoding's.
Abbreviations ("crange", and "cr") are also renamed to "loc".
The traditional "code_location" (a pair of lineno and column) is
renamed to "code_position". Abbreviations are also renamed
(first_loc to beg_pos, and last_loc to end_pos).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because the purpose is now unsure (maybe, to support very old bison?).
If an issue occurs, it should be resurrected with explicit comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because the part of the code is already within `#ifndef RIPPER`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: These nodes are created with `@$` locations.
Start position of `@$` is same as start position of `@1`.
And NEW_XXX macros set first_loc.lineno of a passed
code range to nd_line. So these nd_set_line are not needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
"loc" was ambiguous; it might refer both a location and a code range.
This change uses "loc" for a location, and "crange" or "cr" for a code
range.
A location (abbr. loc) is a point in a program and consists of line
number and column number. A code range (abbr. crange and cr) is a range
within a program and consists of a pair of locations which is the first
and the last.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (block_append_gen): Use nd_loc of
head(tail) when create NEW_BLOCK of head(tail).
e.g. The locations of the NODE_BLOCK is fixed:
```
BEGIN {
:a
}
BEGIN {
:b
}
```
* Before
```
NODE_BLOCK (line: 5, code_range: (5,0)-(7,1))
```
* After
```
NODE_BLOCK (line: 1, code_range: (1,0)-(7,1))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Follow up of r61676. r61676 removed
ruby_sourceline from some actions. When stop to
use lineno of "n th" symbol, it's better to
use last location's lineno of "n-1 th" symbol.
e.g.
```
primary : k_begin {} bodystmt k_end
```
Before r61676 we use lineno of `@2` (ruby_sourceline).
In this case, last location's lineno of `k_begin` (`@1`)
is suitable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
I think that recycling the delimiter string objects doesn't pay its
complexity.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (NULL_LOC): We will create NODEs only
inside of parse.y, so make NULL_LOC to be internal.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change initializes nd_line, lineno of each node, by default, by
using the first line number of code range that bison tracks, instead of
extracting from lexer state.
The lexer state basically provides only the last line number of code
range, so many hacks are used to approximate the first line number. The
hacks have been introduced on demand, or very ad-hocly. I think this
change will make it possible to remove most of the hacks.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (new_qcall): set nd_line to the method name location.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Also, use method_add_block instead of direct modification to nd_iter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NODE_PRELUDE contains a `BEGIN` node, a main node, and compile_option.
This node is assumed that it must be located immediately under the root
NODE_SCOPE, but this strange assumption is not so good, IMO.
This change removes the assumtion; it integrates the former two nodes by
block_append, and moves compile_option into rb_ast_body_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yyerror): use the given location as the end of
erred code, instead of the current position.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yyerror): consider the case first_loc and
last_loc point different lines.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yyerror): utilize the location given by bison.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (gettable_gen): warn for __FILE__/__LINE__ when eval
with binding only. promote use of Binding#source_location
instead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This change (ad-hocly) adjusts the code range of NODE_SCOPE in
class/module definition because the same adjust is already done in
method definition. I intend to just remove inconsistency between
class/module definition and method definition, but this kind of adjust
is dirty, so it should be fixed later (maybe in 2.6).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yylex): deal with end of script chars just after
ignored newline as other places. [ruby-core:84349] [Bug #14206]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Because top_stmts is generated from none (not "/* none */"),
@0 is not set by YYLLOC_DEFAULT. So @0 is a meaningless location.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Change the last location of none to be
equal to the first location of none.
Sometimes none has length (`parser->tokp` does not
match `lex_p` when none is generated).
This leads to invalid code_ranges.
e.g. The locations of the NODE_CALL (:sort) is fixed:
```
x.sort.join(" ")
```
* Before
```
NODE_CALL (line: 1, code_range: (1,0)-(1,7))
```
* After
```
NODE_CALL (line: 1, code_range: (1,0)-(1,6))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Currently the location of do_body is set
by new_do_body. Sometimes the last part of do_body is
none, because bodystmt ends with opt_ensure.
Token keyword_end has been looked ahead when a tokenizer
generates none, so the last location of opt_ensure matches
the last location of `end`. But this relation will be
broken when we change the last location of none to be equal to
the first location of none. So set locations of nd_body in
NODE_ITER explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of mlhs_item
(exclude ',' form range).
e.g. The locations of the NODE_ARRAY is fixed:
```
(a,) = 1,2
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,1)-(1,3))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,1)-(1,2))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (match_op_gen): Fix to only include a range of node2.
e.g. The locations of the NODE_ARRAY is fixed:
```
re =~ s1
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,0)-(1,8))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,6)-(1,8))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of assocs
(exclude ',' form range).
e.g. The locations of the NODE_ARRAY is fixed:
```
m1(str: "bar",)
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,3)-(1,14))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,3)-(1,13))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of assocs.
e.g. The locations of the NODE_ARRAY is fixed:
```
m1(str: "bar", &blk)
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,3)-(1,19))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,3)-(1,13))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Change the last location of NODE_DVAR to
be equal to the first location of NODE_DVAR.
NODE_DVAR of NODE_MASGN (nd_value) is an internal variable,
so it has no length.
e.g. The locations of the NODE_DVAR is changed:
```
a.b {|(c,d)| e}
```
* Before
```
NODE_DVAR (line: 1, code_range: (1,7)-(1,10))
```
* After
```
NODE_DVAR (line: 1, code_range: (1,7)-(1,7))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (evstr2dstr_gen): Fix to only include a range of node.
e.g. The locations of the NODE_DSTR is fixed:
```
%W[a #{b} c]
```
* Before
```
NODE_DSTR (line: 1, code_range: (1,3)-(1,9))
```
* After
```
NODE_DSTR (line: 1, code_range: (1,5)-(1,9))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of bodystmt.
e.g. The locations of the NODE_SCOPE is fixed:
```
module M
def m
end
end
```
* Before
```
NODE_SCOPE (line: 4, code_range: (1,0)-(4,3))
```
* After
```
NODE_SCOPE (line: 4, code_range: (1,8)-(4,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range from primary_value to tCONSTANT.
e.g. The locations of the NODE_COLON2 is fixed:
```
A::B ||= 1
```
* Before
```
NODE_COLON2 (line: 1, code_range: (1,0)-(1,10))
```
* After
```
NODE_COLON2 (line: 1, code_range: (1,0)-(1,4))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (list_append_gen): Change the first location to
start with the location of item if new list is generated.
e.g. The locations of the NODE_ARRAY is changed:
```
"#{a}.#{b}"
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,0)-(1,6))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,5)-(1,6))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (arg_append_gen): Fix to only include a range of
node2 if new list is generated.
e.g. The locations of the NODE_ARRAY is fixed:
```
x.default = 5
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,0)-(1,13))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,12)-(1,13))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Change to only include a range from exc_var to compstmt.
e.g. The locations of the NODE_BLOCK is changed:
```
begin
:a
rescue E => e
:b
end
```
* Before
```
NODE_BLOCK (line: 3, code_range: (3,0)-(5,3))
```
* After
```
NODE_BLOCK (line: 3, code_range: (3,9)-(4,4))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of bodystmt.
e.g. The locations of the NODE_SCOPE is fixed:
```
class << []
def m; end
end
```
* Before
```
NODE_SCOPE (line: 3, code_range: (1,0)-(3,3))
```
* After
```
NODE_SCOPE (line: 3, code_range: (2,2)-(3,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of arg1.
e.g. The locations of the NODE_ARRAY is fixed:
```
1 + 2
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,0)-(1,5))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,4)-(1,5))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of bodystmt.
e.g. The locations of the NODE_SCOPE is fixed:
```
class A
def a; end
end
```
* Before
```
NODE_SCOPE (line: 3, code_range: (1,0)-(3,3))
```
* After
```
NODE_SCOPE (line: 3, code_range: (1,7)-(3,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range from modifier_rescue
to stmt (or arg).
e.g. The locations of the NODE_RESBODY is fixed:
```
a rescue 1
```
* Before
```
NODE_RESBODY (line: 1, code_range: (1,0)-(1,10))
```
* After
```
NODE_RESBODY (line: 1, code_range: (1,2)-(1,10))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to include locations of tSTRING_BEG and tSTRING_END.
e.g. The locations of the NODE_STR is fixed:
```
"a"
```
* Before
```
NODE_STR (line: 1, code_range: (1,1)-(1,2))
```
* After
```
NODE_STR (line: 1, code_range: (1,0)-(1,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (make_array): Set locations of ary to
include locations of start token (tLBRACK, tWORDS_BEG, ...)
and end token (']', tSTRING_END, ...) of array.
e.g. The locations of the NODE_ARRAY is fixed:
```
[1, 2, 3]
```
* Before
```
NODE_ARRAY (line: 1, code_range: (1,1)-(1,8))
```
* After
```
NODE_ARRAY (line: 1, code_range: (1,0)-(1,9))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (arg_value): initialization of aggregation type with
non-constant values is not allowed in C89.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range from tSTRING_BEG to tLABEL_END.
e.g. The locations of the NODE_LIT is fixed:
```
{ "a": 10 }
```
* Before
```
NODE_LIT (line: 1, code_range: (1,2)-(1,9))
```
* After
```
NODE_LIT (line: 1, code_range: (1,2)-(1,6))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (dsym_node_gen): Always set locations
to include locations of tSYMBEG and tSTRING_END.
e.g. The locations of the NODE_LIT is fixed:
```
:"a"
```
* Before
```
NODE_LIT (line: 1, code_range: (1,2)-(1,3))
```
* After
```
NODE_LIT (line: 1, code_range: (1,0)-(1,4))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (new_regexp_gen): Always set locations
to include locations of tREGEXP_BEG and tREGEXP_END.
e.g. The locations of the NODE_LIT is fixed:
```
/a/
```
* Before
```
NODE_LIT (line: 1, code_range: (1,1)-(1,2))
```
* After
```
NODE_LIT (line: 1, code_range: (1,0)-(1,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (new_xstring_gen): Always set locations
to include locations of tXSTRING_BEG and tSTRING_END.
e.g. The locations of the NODE_XSTR is fixed:
```
`a`
```
* Before
```
NODE_XSTR (line: 1, code_range: (1,1)-(1,2))
```
* After
```
NODE_XSTR (line: 1, code_range: (1,0)-(1,3))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_heredoc_identifier):
Put length of term at the head of rb_strterm_heredoc_struct.term.
* parse.y (rb_parser_set_location_from_strterm_heredoc):
Use length of term to calculate first_loc.column.
e.g. The locations of the NODE_DSTR is fixed:
```
a <<STR
123
#{:a}
STR
```
* Before
```
NODE_DSTR (line: 3, code_range: (1,3)-(1,7))
```
* After
```
NODE_DSTR (line: 3, code_range: (1,2)-(1,7))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (rb_parser_set_location_from_strterm_heredoc):
Set locations based on rb_strterm_heredoc_t.
* parse.y (yylex): Set yylloc based on rb_strterm_heredoc_t
when parsing heredoc.
e.g. The locations of the NODE_DSTR is changed:
```
a <<STR
123
#{:a}
STR
```
* Before
```
NODE_DSTR (line: 3, code_range: (3,0)-(1,7))
```
* After
```
NODE_DSTR (line: 3, code_range: (1,3)-(1,7))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (nd_set_loc): set nd_line of the newly created node to
the first location.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (call_uni_op): set nd_line to the unary operator
location, same as non-operator method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (logop): set nd_line to the logical operator location,
same as non-operator method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (match_op): set nd_line to the match operator location,
same as non-operator method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (call_bin_op): set nd_line to the binary operator
location, same as non-operator method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of exc_var.
e.g. The locations of the NODE_DASGN_CURR and NODE_ERRINFO are fixed:
```
begin
1
rescue => e
2
end
```
* Before
```
NODE_DASGN_CURR (line: 3, first_lineno: 3, first_column: 0, last_lineno: 5, last_column: 3)
NODE_ERRINFO (line: 5, first_lineno: 3, first_column: 0, last_lineno: 5, last_column: 3)
```
* After
```
NODE_DASGN_CURR (line: 3, first_lineno: 3, first_column: 7, last_lineno: 3, last_column: 11)
NODE_ERRINFO (line: 5, first_lineno: 3, first_column: 7, last_lineno: 3, last_column: 11)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (arg_append_gen): Update the last location of
NODE_BLOCK_PASS when NODE is appended to nd_head.
e.g. The locations of the NODE_BLOCK_PASS is fixed:
```
o[1, &bl] = :c
```
* Before
```
NODE_BLOCK_PASS (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 8)
```
* After
```
NODE_BLOCK_PASS (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 14)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (arg_append_gen): Update the last location of
NODE_ARGSCAT when NODE is appended to nd_body.
e.g. The locations of the NODE_ARGSCAT is fixed:
```
m(*a, :b, :c)
```
* Before
```
NODE_ARGSCAT (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 8)
```
* After
```
NODE_ARGSCAT (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 12)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix the first location to be equal to the location
of the first element of NODE_ARRAY.
e.g. The locations of the NODE_ARRAY is fixed:
```
m(*a, :b, :c)
```
* Before
```
NODE_ARRAY (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 12)
```
* After
```
NODE_ARRAY (line: 1, first_lineno: 1, first_column: 6, last_lineno: 1, last_column: 12)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of opt_call_args.
e.g. The locations of the NODE_ZARRAY is fixed:
```
a[] ||= 1
```
* Before
```
NODE_ZARRAY (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 9)
```
* After
```
NODE_ZARRAY (line: 1, first_lineno: 1, first_column: 2, last_lineno: 1, last_column: 3)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (new_args_tail_gen): Set only a location of NODE_DVAR.
e.g. The locations of the NODE_DVAR is fixed:
```
def a(k: 1, **kws) end
```
* Before
```
NODE_DVAR (line: 1, first_lineno: 1, first_column: 6, last_lineno: 1, last_column: 18)
```
* After
```
NODE_DVAR (line: 1, first_lineno: 1, first_column: 12, last_lineno: 1, last_column: 17)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (top_stmt): wrap BEGIN statement to store the whole
location for each block.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix to only include a range of the first argument of cond.
e.g. The locations of the NODE_MATCH2 and NODE_GVAR are fixed:
```
1 while /#{:a}/
```
* Before
```
NODE_MATCH2 (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 15)
NODE_GVAR (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 15)
```
* After
```
NODE_MATCH2 (line: 1, first_lineno: 1, first_column: 8, last_lineno: 1, last_column: 15)
NODE_GVAR (line: 1, first_lineno: 1, first_column: 8, last_lineno: 1, last_column: 15)
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e