From ba731b19ca181c857867dc7e8c383757415e2afe Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 12 Jul 2023 13:50:43 -0400 Subject: [PATCH] Move public types to the top --- assets/parser.d.erb | 64 +++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/assets/parser.d.erb b/assets/parser.d.erb index 8c511bb..4d7d1b1 100644 --- a/assets/parser.d.erb +++ b/assets/parser.d.erb @@ -1,14 +1,27 @@ +/** + * @file + * + * This file is generated by Propane. + */ + <% if @grammar.modulename %> module <%= @grammar.modulename %>; <% end %> - import std.stdio; +/************************************************************************** + * User code blocks + *************************************************************************/ + <% @grammar.code_blocks.each do |code| %> <%= code %> <% end %> +/************************************************************************** + * Public types + *************************************************************************/ + /* Result codes. */ public enum : size_t { @@ -20,9 +33,6 @@ public enum : size_t P_EOF, } -/* An invalid ID value. */ -private enum size_t INVALID_ID = cast(size_t)-1; - /** Token ID type. */ public alias Token = <%= get_type_for(@grammar.invalid_token_id) %>; @@ -38,13 +48,6 @@ public enum : Token INVALID_TOKEN_ID = <%= @grammar.invalid_token_id %>, } -/** Token names. */ -public static immutable string[] token_names = [ -<% @grammar.tokens.each_with_index do |token, index| %> - "<%= token.name %>", -<% end %> -]; - /** Code point type. */ public alias CodePoint = uint; @@ -70,6 +73,35 @@ public static struct Position uint col; } +/** + * Lexed token information. + */ +public static struct TokenInfo +{ + Position position; + size_t length; + Token token; + ParserValue pvalue; +} + +/************************************************************************** + * Public data + *************************************************************************/ + +/** Token names. */ +public static immutable string[] token_names = [ +<% @grammar.tokens.each_with_index do |token, index| %> + "<%= token.name %>", +<% end %> +]; + +/************************************************************************** + * Private types + *************************************************************************/ + +/* An invalid ID value. */ +private enum size_t INVALID_ID = cast(size_t)-1; + /************************************************************************** * Decoder *************************************************************************/ @@ -216,14 +248,6 @@ private static immutable Mode[] modes = [ <% end %> ]; -public static struct TokenInfo -{ - Position position; - size_t length; - Token token; - ParserValue pvalue; -} - public static class Lexer { private string m_input; @@ -349,7 +373,7 @@ public static class Lexer } } - struct MatchInfo + private struct MatchInfo { size_t length; Position delta_position;