summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEarlopain <14981592+Earlopain@users.noreply.github.com>2026-01-16 11:52:39 +0100
committergit <svn-admin@ruby-lang.org>2026-01-16 12:07:41 +0000
commit074a23ab77a94a5388958c573ab33d5ea5a46ecc (patch)
tree69cf5142834accbba6adc224176120d663a4eadb /lib
parentf872901bb263e01768ac64e6d063377c3b633e27 (diff)
[ruby/prism] Add `Ripper.tokenize` to translation layer
It's public API and trivial to implement. https://github.com/ruby/prism/commit/e77545f8b5
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/ripper.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index a901a72692..6552d2dbb8 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -78,6 +78,19 @@ module Prism
end
end
+ # Tokenizes the Ruby program and returns an array of strings.
+ # The +filename+ and +lineno+ arguments are mostly ignored, since the
+ # return value is just the tokenized input.
+ # By default, this method does not handle syntax errors in +src+,
+ # use the +raise_errors+ keyword to raise a SyntaxError for an error in +src+.
+ #
+ # p Ripper.tokenize("def m(a) nil end")
+ # # => ["def", " ", "m", "(", "a", ")", " ", "nil", " ", "end"]
+ #
+ def self.tokenize(...)
+ lex(...).map(&:value)
+ end
+
# This contains a table of all of the parser events and their
# corresponding arity.
PARSER_EVENT_TABLE = {