From 1dcdd87a28ef6219fa2c8495d80a179d530b90ad Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 6 Jul 2021 10:28:35 -0400 Subject: [PATCH] Generate token constants and names to top-level parser class --- assets/parser.d.erb | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/assets/parser.d.erb b/assets/parser.d.erb index 3da6bbd..82fa03f 100644 --- a/assets/parser.d.erb +++ b/assets/parser.d.erb @@ -4,6 +4,29 @@ module <%= @grammar.modulename %>; <% end %> class <%= classname %> { + enum + { +<% @grammar.tokens.each_with_index do |token, index| %> +<% if token.name %> + TOKEN_<%= token.c_name %> = <%= index %>, +<% end %> +<% end %> + TOKEN_EOF = <%= TOKEN_EOF %>, + TOKEN_DECODE_ERROR = <%= TOKEN_DECODE_ERROR %>, + TOKEN_DROP = <%= TOKEN_DROP %>, + TOKEN_NONE = <%= TOKEN_NONE %>, + } + + static immutable string TokenNames[] = [ +<% @grammar.tokens.each_with_index do |token, index| %> +<% if token.name %> + "<%= token.name %>", +<% else %> + null, +<% end %> +<% end %> + ]; + class Decoder { enum @@ -71,29 +94,6 @@ class <%= classname %> static class Lexer { - enum - { -<% @grammar.tokens.each_with_index do |token, index| %> -<% if token.name %> - TOKEN_<%= token.c_name %> = <%= index %>, -<% end %> -<% end %> - TOKEN_EOF = <%= TOKEN_EOF %>, - TOKEN_DECODE_ERROR = <%= TOKEN_DECODE_ERROR %>, - TOKEN_DROP = <%= TOKEN_DROP %>, - TOKEN_NONE = <%= TOKEN_NONE %>, - } - - static immutable string TokenNames[] = [ -<% @grammar.tokens.each_with_index do |token, index| %> -<% if token.name %> - "<%= token.name %>", -<% else %> - null, -<% end %> -<% end %> - ]; - private struct Transition { uint first;