From 6c5f690da4a18347c7e1c2269edea2f4e0ae029a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 8 Apr 2020 08:53:19 +0200 Subject: [PATCH] d: improvements on symbol kinds public enum SymbolKind { S_YYEMPTY = -2, /* No symbol. */ S_YYEOF = 0, /* $end */ S_YYERROR = 1, /* error */ S_YYUNDEF = 2, /* $undefined */ S_EQ = 3, /* "=" */ * data/skeletons/d.m4 (api.symbol.prefix): Default to S_. Output the symbol kind definitions with a comment. --- data/skeletons/d.m4 | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/data/skeletons/d.m4 b/data/skeletons/d.m4 index 7d1672d5..4c3a5ce7 100644 --- a/data/skeletons/d.m4 +++ b/data/skeletons/d.m4 @@ -148,11 +148,9 @@ private static immutable b4_int_type_for([$2])[[]] yy$1_ = ]) -## -------------------------- ## -## (External) token numbers. ## -## -------------------------- ## - -b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]]) +## ------------- ## +## Token kinds. ## +## ------------- ## # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) # --------------------------------------- @@ -165,7 +163,7 @@ m4_define([b4_token_enum], # -------------- # Output the definition of the tokens as enums. m4_define([b4_token_enums], -[/* Tokens. */ +[/* Token kinds. */ public enum YYTokenType { /** Token returned by the scanner to signal the end of its input. */ @@ -174,19 +172,24 @@ b4_symbol_foreach([b4_token_enum]) } ]) -## --------------------------- ## -## (Internal) symbol numbers. ## -## --------------------------- ## + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) # b4_symbol_enum(SYMBOL-NUM) # -------------------------- # Output the definition of this symbol as an enum. m4_define([b4_symbol_enum], -[m4_ifval(b4_symbol([$1], [kind]), - [m4_format([[%s = %s]], - b4_symbol([$1], [kind]), - b4_symbol([$1], [number]))])]) +[m4_format([ %-30s %s], + m4_format([[%s = %s,]], + b4_symbol([$1], [kind]), + [$1]), + [b4_symbol_tag_comment([$1])])]) # b4_declare_symbol_enum @@ -195,14 +198,12 @@ m4_define([b4_symbol_enum], # Defining YYEMPTY here is important: it forces the compiler # to use a signed type, which matters for yytoken. m4_define([b4_declare_symbol_enum], -[[ /* Symbol type. */ +[[ /* Symbol kinds. */ public enum SymbolKind { - ]m4_join([, - ], - ]b4_symbol_kind([-2])[ = -2, - b4_symbol_map([b4_symbol_enum]))[ - }; + ]b4_symbol_kind([-2])[ = -2, /* No symbol. */ +]b4_symbol_foreach([b4_symbol_enum])dnl +[ }; ]])])