Skip to content

Commit

Permalink
Merge pull request #64 from Maumagnaguagno/refactor-grammar-symbol
Browse files Browse the repository at this point in the history
Refactor Lrama::Grammar::Symbol
  • Loading branch information
yui-knk authored Aug 6, 2023
2 parents c9b59a2 + 6a91e6b commit 53488c3
Showing 1 changed file with 3 additions and 11 deletions.
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

0 comments on commit 53488c3

Please sign in to comment.