[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
traces: use colors for the semantic values
From: |
Akim Demaille |
Subject: |
traces: use colors for the semantic values |
Date: |
Sat, 27 Apr 2019 18:28:24 +0200 |
commit f0240973093e46fd830f74f90659d649ffb50308
Author: Akim Demaille <address@hidden>
Date: Sat Apr 27 16:41:07 2019 +0200
traces: use colors for the semantic values
This makes reading the trace slightly easier. It would be very nice
to highlight the "big steps", especially reductions. But this is a
private experiment: do not use it.
* data/diagnostics.css (value): New.
* src/parse-gram.y: Use no delimiters and no c quotation for strings
to facilitate debugging.
(tron, troff, TRACE): New.
Not very elegant, but until there is support for printf-formats in
libtextstyle, it shall be enough.
diff --git a/data/diagnostics.css b/data/diagnostics.css
index 515802ec..7136a80b 100644
--- a/data/diagnostics.css
+++ b/data/diagnostics.css
@@ -6,3 +6,5 @@
.warning { color: purple; }
.error { color: red; }
.note { color: cyan; }
+/* Semantic values in Bison's parser traces. */
+.value { color: green; }
diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 5987232d..fcf58a84 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -544,8 +544,10 @@ m4_if(b4_skeleton, ["yacc.c"],
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
# endif
]])dnl
- b4_symbol_actions([printer])[
-}
+b4_percent_code_get([[pre-printer]])dnl
+ b4_symbol_actions([printer])
+b4_percent_code_get([[post-printer]])dnl
+[}
/*---------------------------.
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 62ae80da..5a77c692 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -87,8 +87,8 @@ b4_output_begin([b4_parser_file_name])[
]])[
]b4_user_pre_prologue[
]b4_user_post_prologue[
-]b4_percent_code_get([[imports]])
-[/**
+]b4_percent_code_get([[imports]])[
+/**
* A Bison parser, automatically generated from
<tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
*
* @@author LALR (1) parser skeleton written by Paolo Bonzini.
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 1c2199dc..263db619 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -112,6 +112,10 @@
#define YYTYPE_INT8 int_fast8_t
#define YYTYPE_UINT16 uint_fast16_t
#define YYTYPE_UINT8 uint_fast8_t
+
+ /* Add style to semantic values in traces. */
+ static void tron (FILE *yyo);
+ static void troff (FILE *yyo);
}
%define api.header.include {"parse-gram.h"}
@@ -202,12 +206,15 @@
%token TAG_ANY "<*>"
%token TAG_NONE "<>"
+ /* Experimental feature, don't rely on it. */
+%code pre-printer {tron (yyo);}
+%code post-printer {troff (yyo);}
+
%type <unsigned char> CHAR
%printer { fputs (char_name ($$), yyo); } <unsigned char>
%type <char*> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
-%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
-%printer { fprintf (yyo, "{\n%s\n}", $$); } <char*>
+%printer { fputs ($$, yyo); } <char*>
%type <uniqstr>
BRACKETED_ID ID ID_COLON
@@ -1054,3 +1061,13 @@ current_lhs (symbol *sym, location loc, named_ref *ref)
free (current_lhs_named_ref);
current_lhs_named_ref = ref;
}
+
+static void tron (FILE *yyo)
+{
+ begin_use_class ("value", yyo);
+}
+
+static void troff (FILE *yyo)
+{
+ end_use_class ("value", yyo);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- traces: use colors for the semantic values,
Akim Demaille <=