Skip to content

Commit a888e55

Browse files
committed
Also dedup identifiers in Ruby parser
1 parent b0bb9e4 commit a888e55

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

benchmark/run.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def self.profile_to_definition
488488
end
489489

490490
def self.profile_from_definition
491-
require "graphql/c_parser"
491+
# require "graphql/c_parser"
492492
schema_str = SILLY_LARGE_SCHEMA.to_definition
493493

494494
Benchmark.ips do |x|

graphql-c_parser/graphql-c_parser.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
1212
s.authors = ["Robert Mosolgo"]
1313
s.email = ["[email protected]"]
1414
s.license = "MIT"
15-
s.required_ruby_version = ">= 2.4.0"
15+
s.required_ruby_version = ">= 3.0.0"
1616
s.metadata = {
1717
"homepage_uri" => "https://graphql-ruby.org",
1818
"changelog_uri" => "https://github.com/rmosolgo/graphql-ruby/blob/master/graphql-c_parser/CHANGELOG.md",

lib/graphql/language/parser.rb

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def initialize(graphql_str, filename: nil, trace: Tracing::NullTrace)
3535
@graphql_str = graphql_str
3636
@filename = filename
3737
@trace = trace
38+
@dedup_identifiers = false
3839
end
3940

4041
def parse
@@ -732,6 +733,9 @@ def raise_parse_error(message)
732733
# Only use when we care about the expected token's value
733734
def expect_token_value(tok)
734735
token_value = @lexer.token_value
736+
if @dedup_identifiers
737+
token_value = -token_value
738+
end
735739
expect_token(tok)
736740
token_value
737741
end
@@ -741,6 +745,12 @@ def expect_token_value(tok)
741745
def debug_token_value
742746
@lexer.debug_token_value(token_name)
743747
end
748+
class SchemaParser < Parser
749+
def initialize(*args, **kwargs)
750+
super
751+
@dedup_identifiers = true
752+
end
753+
end
744754
end
745755
end
746756
end

0 commit comments

Comments
 (0)