[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/6] examples: do not rely on YY_LOCATION_PRINT
From: |
Akim Demaille |
Subject: |
[PATCH 2/6] examples: do not rely on YY_LOCATION_PRINT |
Date: |
Tue, 9 Feb 2021 07:15:42 +0100 |
* examples/c/bistromathic/parse.y (location_print): New.
Use it.
---
examples/c/bistromathic/parse.y | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index b772f1baf..ad025e66b 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -94,6 +94,10 @@
// Emitted in the implementation file.
%code {
+ // Print *LOC on OUT.
+ static void location_print (FILE *out, YYLTYPE const * const loc);
+ #define YY_LOCATION_PRINT(Out, Loc) location_print(Out, &(Loc))
+
#if defined ENABLE_NLS && ENABLE_NLS
# define _(Msgid) gettext (Msgid)
#else
@@ -269,6 +273,26 @@ symbol_count (void)
}
+
+/*------------.
+| Locations. |
+`------------*/
+
+// Print *LOC on OUT. Do it in a compact way, that avoids redundancy.
+
+static void
+location_print (FILE *out, YYLTYPE const * const loc)
+{
+ fprintf (out, "%d.%d", loc->first_line, loc->first_column);
+
+ int end_col = 0 != loc->last_column ? loc->last_column - 1 : 0;
+ if (loc->first_line < loc->last_line)
+ fprintf (out, "-%d.%d", loc->last_line, end_col);
+ else if (loc->first_column < end_col)
+ fprintf (out, "-%d", end_col);
+}
+
+
/*----------.
| Scanner. |
`----------*/
--
2.30.0
- [PATCH 0/6] c: make YYLOCATION_PRINT public, Akim Demaille, 2021/02/09
- [PATCH 1/6] c: stop defining YY_LOCATION_PRINT when locations are not enabled, Akim Demaille, 2021/02/09
- [PATCH 2/6] examples: do not rely on YY_LOCATION_PRINT,
Akim Demaille <=
- [PATCH 3/6] c: rename YY_LOCATION_PRINT as YYLOCATION_PRINT and make it public, Akim Demaille, 2021/02/09
- [PATCH 4/6] examples: use YYLOCATION_PRINT, Akim Demaille, 2021/02/09
- [PATCH 5/6] examples: improve some function prototypes, Akim Demaille, 2021/02/09
- [PATCH 6/6] doc: printing locations, Akim Demaille, 2021/02/09