Remove Token#c_name; use given token case in token constants

This commit is contained in:
Josh Holtrop 2022-09-25 14:48:49 -04:00
parent 01c9340819
commit 4d716f6c10
3 changed files with 8 additions and 12 deletions

View File

@ -10,7 +10,7 @@ class <%= @classname %>
enum
{
<% @grammar.tokens.each_with_index do |token, index| %>
TOKEN_<%= token.c_name %> = <%= index %>,
TOKEN_<%= token.name %> = <%= index %>,
<% end %>
_TOKEN_COUNT = <%= @grammar.tokens.size %>,
_TOKEN_EOF = <%= TOKEN_EOF %>,

View File

@ -30,10 +30,6 @@ class Propane
@line_number = options[:line_number]
end
def c_name
@name.upcase
end
def to_s
@name
end

View File

@ -70,13 +70,13 @@ unittest
alias LT = Testparser.Lexer.LexedToken;
string input = "5 + 4 * \n677 + 567";
Testparser.Lexer lexer = new Testparser.Lexer(cast(const(ubyte) *)input.ptr, input.length);
assert(lexer.lex_token() == LT(0, 0, 1, Testparser.TOKEN_INT));
assert(lexer.lex_token() == LT(0, 2, 1, Testparser.TOKEN_PLUS));
assert(lexer.lex_token() == LT(0, 4, 1, Testparser.TOKEN_INT));
assert(lexer.lex_token() == LT(0, 6, 1, Testparser.TOKEN_TIMES));
assert(lexer.lex_token() == LT(1, 0, 3, Testparser.TOKEN_INT));
assert(lexer.lex_token() == LT(1, 4, 1, Testparser.TOKEN_PLUS));
assert(lexer.lex_token() == LT(1, 6, 3, Testparser.TOKEN_INT));
assert(lexer.lex_token() == LT(0, 0, 1, Testparser.TOKEN_int));
assert(lexer.lex_token() == LT(0, 2, 1, Testparser.TOKEN_plus));
assert(lexer.lex_token() == LT(0, 4, 1, Testparser.TOKEN_int));
assert(lexer.lex_token() == LT(0, 6, 1, Testparser.TOKEN_times));
assert(lexer.lex_token() == LT(1, 0, 3, Testparser.TOKEN_int));
assert(lexer.lex_token() == LT(1, 4, 1, Testparser.TOKEN_plus));
assert(lexer.lex_token() == LT(1, 6, 3, Testparser.TOKEN_int));
assert(lexer.lex_token() == LT(1, 9, 0, Testparser._TOKEN_EOF));
lexer = new Testparser.Lexer(null, 0u);