Currently `Ripper.slice` raises a FrozenError
```ruby
require 'ripper'
p Ripper.slice('foo', 'ident')
```
```
/path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:193:in `concat': can't modify frozen String (FrozenError)
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:193:in `block in compile'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:190:in `scan'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:190:in `compile'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:169:in `initialize'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:151:in `new'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:151:in `token_match'
from /path/to/g/lib/ruby/2.6.0/ripper/lexer.rb:144:in `slice'
from /tmp/tmp.kb4cnhvum2/test.rb:2:in `<main>'
```
This patch will fix the problem.
[Fix GH-1837]
From: Masataka Pocke Kuwabara <kuwabara@pocke.me>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62743 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
To avoid the unspecified behavior (the evaluation order of arguments).
In `$$ = foo(bar(), baz());`, it is unspecified which `bar` or `baz` is
called earlier.
This commit changes the code to `v1=bar(); v2=baz(); $$ = foo();`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61991 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
`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
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
* ext/ripper/lib/ripper/lexer.rb (Ripper::Lexer): added allbits?,
anybits? and nobits? methods, as well as Integer. a patch by
aycabta. [Feature #14170]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): dedent only
strings at the beginning, not strings in middle.
[ruby-core:83343] [Bug #14027]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (List#inspect): splat self data
to local variables same as members of Elem.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (ripper_state): add states of scanner to tokens from
Ripper.lex and Ripper::Filter#on_*. based on the patch by
aycabta (Code Ahss) at [ruby-core:81789]. [Feature #13686]
* ext/ripper/tools/preproc.rb (prelude, usercode): generate EXPR_*
constants from enums.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper.rb: [DOC] fix format of the License
description and the author. patched by aycabta (Code Ahss) at
[ruby-core:82376]. [Bug #13813]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* common.mk (ripper.c): pass the build directory path for id.h
which may be generated there.
* ext/ripper/depend (ripper.y): search the top build directory and
the top source directory.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): replace an
empty string content because of dedentation with :on_ignored_sp.
an empty token makes the sorted order unstable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The order of sed commands in Makefile of ripper was wrong: it tries to
replace `y.tab.c` with `ripper.c`, but before that, ytab.sed replaced
`y.tab.c` with `parse.c`, which led to a wrong result.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): insert
stripped leading spaces as `on_ignored_sp` elements, so that the
original source can be reconsructed.
[ruby-core:80977] [Bug #13536]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): fix for
nested indedented here documents, where `Elem`s are nested too.
[ruby-core:80977] [Bug #13536]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Onigumo 6 (r57045) introduced new onigumo.h header file, which is
required from quite much everywhere. This commit adds necessary
dependencies.
Note: ruby/oniguruma.h now includes onigumo.h,
ruby/io.h includes oniguruma.h,
ruby/encoding.h also includes oniguruma.h,
and internal.h includes encoding.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* tool/gen_dummy_probes.rb: remove include and conditional
directives from probes.dmyh which are removed by preprocessing.
* common.mk: remove unnecessary dependencies on vm_opts.h via
probes.dmyh.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/depend (ripper.E): add missing $(INCFLAGS).
* ext/ripper/tools/strip.rb: insert an empty line for blank or
line directive lines.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb (on_heredoc_dedent): Fix
Ripper.lex error in dedenting squiggly heredoc. heredoc tree is
also an array of Elem in the outer tree. [Fix GH-1234]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
".eventids2.check" as inference one. but nmake is not cheated by macro.
this fixes build failure introduced at r53448. see also the commit log of
r53452.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
avoid mkmf.rb's suffix rule scanner (lib/mkmf.rb:2085), it detects
suffix rule from depend file and adds .SUFFIXES.
It breaks bsdmake to generate check file named ".eventids2.check".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/mkmf.rb (configuration, dummy_makefile, create_makefile):
show library installation messages only when any files need to
be updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/lexer.rb: alias same methods instead of
eval for each events.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/sexp.rb (SexpBuilderPP): share scanner
event handlers and most of parser event handlers with
SexpBuilder.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/ripper/lib/ripper/core.rb: alias same methods instead of
eval for each events.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* defs/id.def, parse.y: Switch internal token name to reflect
current form of safe-call operator. [Fix GH-1090]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e