Skip to content

Commit

Permalink
+ lexer.rl: use Ragel -F0 on non-CRuby (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon authored Dec 15, 2022
1 parent da1a8db commit 645e006
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ tmp
*.output
.ruby-version
.ruby-gemset
lib/parser/lexer.rb
lib/parser/lexer-F0.rb
lib/parser/lexer-F1.rb
lib/parser/ruby18.rb
lib/parser/ruby19.rb
lib/parser/ruby20.rb
Expand Down
3 changes: 2 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
--asset ./doc/css/common.css:css/common.css
--verbose
--api public
--exclude lib/parser/lexer.rb
--exclude lib/parser/lexer-F0.rb
--exclude lib/parser/lexer-F1.rb
--exclude lib/parser/ruby18.rb
--exclude lib/parser/ruby19.rb
--exclude lib/parser/ruby20.rb
Expand Down
9 changes: 7 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ end

task :build => [:generate_release, :changelog]

GENERATED_FILES = %w(lib/parser/lexer.rb
GENERATED_FILES = %w(lib/parser/lexer-F0.rb
lib/parser/lexer-F1.rb
lib/parser/ruby18.rb
lib/parser/ruby19.rb
lib/parser/ruby20.rb
Expand Down Expand Up @@ -151,10 +152,14 @@ task :changelog do
sh('git commit CHANGELOG.md -m "Update changelog." || true')
end

rule '.rb' => '.rl' do |t|
file 'lib/parser/lexer-F1.rb' => 'lib/parser/lexer.rl' do |t|
sh "ragel -F1 -R #{t.source} -o #{t.name}"
end

file 'lib/parser/lexer-F0.rb' => 'lib/parser/lexer.rl' do |t|
sh "ragel -F0 -R #{t.source} -o #{t.name}"
end

rule '.rb' => '.y' do |t|
opts = [ "--superclass=Parser::Base",
t.source,
Expand Down
6 changes: 5 additions & 1 deletion lib/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ module Source

require 'parser/static_environment'

require 'parser/lexer'
if RUBY_ENGINE == 'ruby'
require 'parser/lexer-F1'
else
require 'parser/lexer-F0'
end
require 'parser/lexer/literal'
require 'parser/lexer/stack_state'
require 'parser/lexer/dedenter'
Expand Down
1 change: 1 addition & 0 deletions lib/parser/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class Parser::Lexer
_lex_to_state_actions = klass.send :_lex_to_state_actions
_lex_from_state_actions = klass.send :_lex_from_state_actions
_lex_eof_trans = klass.send :_lex_eof_trans
_lex_actions = klass.send :_lex_actions if klass.respond_to?(:_lex_actions, true)

pe = @source_pts.size + 2
p, eof = @p, pe
Expand Down

0 comments on commit 645e006

Please sign in to comment.