From 5881f1338005267379186c3c4cfb99b8aebaf974 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 23 Jun 2021 22:22:45 -0400 Subject: [PATCH] Generate enum of token identifiers --- assets/parser.d.erb | 6 ++++++ lib/imbecile/grammar/token.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/assets/parser.d.erb b/assets/parser.d.erb index 87e1f18..4bcca7e 100644 --- a/assets/parser.d.erb +++ b/assets/parser.d.erb @@ -4,4 +4,10 @@ module <%= @grammar.modulename %>; <% end %> class <%= classname %> { + enum + { +<% @grammar.tokens.each do |token| %> + TOKEN_<%= token.c_name %>, +<% end %> + } } diff --git a/lib/imbecile/grammar/token.rb b/lib/imbecile/grammar/token.rb index 573744f..aa3fc23 100644 --- a/lib/imbecile/grammar/token.rb +++ b/lib/imbecile/grammar/token.rb @@ -28,6 +28,10 @@ module Imbecile @nfa = regex.nfa end + def c_name + @name.upcase + end + def to_s @name end