Heredocs are parsed line-by-line, so we need to keep track of the
temporary encoding of the string. Previously, a heredoc would
only detect mixed encoding errors if they were on the same line,
this changes things so they will be caught on different lines.
Fixes [Bug #15839]
This allows cases such as:
```ruby
m ->(a = ->{@1}) {a}
m.call.call(1)
m2 ->(a: ->{@1}) {a}
m2.call.call(2)
```
Previously, this would cause a syntax error.
[Bug#15789]
Because `proc{|| @1}` is a syntax error, the following should
also be syntax errors:
```ruby
proc { |
| @1}
```
```ruby
proc { |; a| @1 }
```
This fixes both cases.
[Bug #15825]
* parse.y (heredoc_identifier): CR in here-document identifier
might or might not result in a syntax error, by the EOL code.
make a syntax error regardless of the EOL code.
* parse.y (heredoc_identifier): quoted here-document identifier
must end within the same line.
the only corner case that here-document identifier can contain a
newline is that the closing qoute is placed at the beginning of
the next line, and has been warned since 2.4.
```ruby
<<"EOS
" # warning: here document identifier ends with a newline
EOS
```
* parse.y (internal_id): number the ID serial for internal use by
counting down from the neary maximum value, not to accidentally
match permanent IDs.
[Bug #15768]
* parse.y (parser_append_options): explicitly pass $; when auto
splitting, to suppress the warning for non-nil $;.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (rb_parser_fatal): fix "parser" in the message which was
replaced accidentally. it is not the argument name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because hard to specify commits related to r67479 only.
So please commit again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (rb_parser_fatal): fix "parser" in the message which was
replaced accidentally. it is not the argument name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: show compile error and the error line separately,
instead of building the error message by snprintf then yyerror.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_token_value_print): in ripper, ID values are
wrapped in NODE_RIPPER at set_yylval_name(), so print the Symbol
wrapped together.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (lambda): support numbered parameters, only when no
argument list including empty parentheses, like empty vertical
bars. [ruby-core:91859] [Bug #15672]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (set_yylval_noname): continue after an invalid global,
instance, class variable name, without "unexpected end-of-file"
error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_numbered_param): hoisted out the contextual
check for numbered parameters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_atmark): exclude punctuation follows @ marks,
whereas it is inclusive after $ mark as some punctuation global
variables exist.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_gvar): show the source line erred by invalid
global variable, and indicate the variable including the wrong
punctuation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (ruby_show_error_line): hoisted out from parser_yyerror.
* parse.y (regx_options): revert r67226 and show the error line
separately.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parser_yyerror): trim a newline at the end of the erred
code which was replaced with an extra space in the succeeding
cursor line.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_string): bail out when word-list meets end of
input not to show an extra "unexpected" error message after the
preceding error.
$ ruby -e "%w["
-e:1: unterminated string meets end of file
-e:1: syntax error, unexpected terminator, expecting ' '
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
yystpcpy is always used by yysyntax_error in bison 2.3, but may
not used by other than yytnamerr in newer bison.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (rb_yytnamerr): strip enclosing double-quotes, same as
the default yytnamerr except for that single-quotes matching
back-quotes do not stop stripping.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (symbol): turned into a node, as well as `numeric`, for
a symbol literal, and includes `dsym` now.
* parse.y (ssym): previous `symbol`. renamed as the counterpart
of `dsym`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: refine error messages for tSYMBEG and tSTRING_BEG, which
can appear at invalid places.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: Fix the beginning position of trailing NODE_UNDEF.
e.g. The location of the NODE_UNDEF for `b` is fixed:
```
undef a, b
```
* Before
```
NODE_UNDEF (line: 1, location: (1,6)-(1,10))
```
* After
```
NODE_UNDEF (line: 1, location: (1,9)-(1,10))
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
which usually refers ruby_sourcefile_string and is not freed
directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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