Generate token constants and names to top-level parser class
This commit is contained in:
parent
8aec7ec0de
commit
1dcdd87a28
@ -4,6 +4,29 @@ module <%= @grammar.modulename %>;
|
|||||||
<% end %>
|
<% end %>
|
||||||
class <%= classname %>
|
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
|
class Decoder
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
@ -71,29 +94,6 @@ class <%= classname %>
|
|||||||
|
|
||||||
static class Lexer
|
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
|
private struct Transition
|
||||||
{
|
{
|
||||||
uint first;
|
uint first;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user