Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Lrama::Grammar::Symbol #64

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions lib/lrama/grammar/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def accept_symbol?
end

def display_name
if alias_name
alias_name
else
id.s_value
end
alias_name || id.s_value
end

# name for yysymbol_kind_t
Expand All @@ -51,11 +47,7 @@ def enum_name
when eof_symbol?
name = "YYEOF"
when term? && id.type == Token::Char
if alias_name
name = number.to_s + alias_name
else
name = number.to_s + id.s_value
end
name = number.to_s + display_name
when term? && id.type == Token::Ident
name = id.s_value
when nterm? && (id.s_value.include?("$") || id.s_value.include?("@"))
Expand All @@ -66,7 +58,7 @@ def enum_name
raise "Unexpected #{self}"
end

"YYSYMBOL_" + name.gsub(/[^a-zA-Z_0-9]+/, "_")
"YYSYMBOL_" + name.gsub(/\W+/, "_")
end

# comment for yysymbol_kind_t
Expand Down