Skip to content

Commit 35dceb5

Browse files
authored
Merge pull request #3443 from Earlopain/parser-translator-builder
Add a custom builder class for the parser translator
2 parents 802e7ef + b080e60 commit 35dceb5

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

lib/prism/translation/parser.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def initialize(message, level, reason, location)
3131
end
3232
end
3333

34+
# Create the parser with our custom builder class
35+
def initialize(builder = Parser::Builder.new)
36+
super
37+
end
38+
3439
Racc_debug_parser = false # :nodoc:
3540

3641
# By using the `:parser` keyword argument, you can translate in a way that is compatible with
@@ -342,6 +347,7 @@ def convert_for_prism(version)
342347
end
343348
end
344349

350+
require_relative "parser/builder"
345351
require_relative "parser/compiler"
346352
require_relative "parser/lexer"
347353

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module Prism
4+
module Translation
5+
class Parser
6+
# A builder that knows how to convert more modern Ruby syntax
7+
# into whitequark/parser gem's syntax tree.
8+
class Builder < ::Parser::Builders::Default
9+
10+
end
11+
end
12+
end
13+
end

prism.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Gem::Specification.new do |spec|
9898
"lib/prism/translation/parser33.rb",
9999
"lib/prism/translation/parser34.rb",
100100
"lib/prism/translation/parser35.rb",
101+
"lib/prism/translation/parser/builder.rb",
101102
"lib/prism/translation/parser/compiler.rb",
102103
"lib/prism/translation/parser/lexer.rb",
103104
"lib/prism/translation/ripper.rb",

test/prism/ruby/parser_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# First, opt in to every AST feature.
1818
Parser::Builders::Default.modernize
19+
Prism::Translation::Parser::Builder.modernize
1920

2021
# The parser gem rejects some strings that would most likely lead to errors
2122
# in consumers due to encoding problems. RuboCop however monkey-patches this

0 commit comments

Comments
 (0)