]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: parser: reorder bison incarnations
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 01:10:48 +0000 (02:10 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 19:42:01 +0000 (20:42 +0100)
This shuffles the code blocks in command_parser.y to match file output
order, then adjusts things to make the include handling less messy.

(also dropped unused DECIMAL_STRLEN_MAX define.)

This should hopefully fix the build on NetBSD 6.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command_lex.l
lib/command_parse.y

index e978803b2213e8cf27ad277366cfc8a9993dfd26..0cb306b6828d225ff3cbe6852ec16ea7f00818b6 100644 (file)
@@ -24,7 +24,6 @@
 
 %{
 #include "command_parse.h"
-#define YYSTYPE CMD_YYSTYPE
 %}
 
 WORD            (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]*
index d2dd5aa5cc3a57717347fabf196a02fd6ed19661..81aa8a04e77cb81cf48c229b071ecc83ef6cf93a 100644 (file)
  */
 
 %{
-
-typedef union CMD_YYSTYPE CMD_YYSTYPE;
-#define YYSTYPE CMD_YYSTYPE
-#include "command_lex.h"
-
 // compile with debugging facilities
 #define YYDEBUG 1
 %}
@@ -39,7 +34,13 @@ typedef union CMD_YYSTYPE CMD_YYSTYPE;
 %defines "command_parse.h"
 %output  "command_parse.c"
 
-/* required external units */
+/* note: code blocks are output in order, to both .c and .h:
+ *  1. %code requires
+ *  2. %union + bison forward decls
+ *  3. %code provides
+ * command_lex.h needs to be included at 3.; it needs the union and YYSTYPE.
+ * struct parser_ctx is needed for the bison forward decls.
+ */
 %code requires {
   #include "stdlib.h"
   #include "string.h"
@@ -47,6 +48,25 @@ typedef union CMD_YYSTYPE CMD_YYSTYPE;
   #include "log.h"
   #include "graph.h"
 
+  #define YYSTYPE CMD_YYSTYPE
+  struct parser_ctx;
+}
+
+%union {
+  long long number;
+  char *string;
+  struct graph_node *node;
+  struct subgraph *subgraph;
+}
+
+%code provides {
+  #ifndef FLEX_SCANNER
+  #include "command_lex.h"
+  #endif
+
+  extern void set_lexer_string (yyscan_t *scn, const char *string);
+  extern void cleanup_lexer (yyscan_t *scn);
+
   struct parser_ctx {
     yyscan_t scanner;
 
@@ -58,23 +78,6 @@ typedef union CMD_YYSTYPE CMD_YYSTYPE;
     /* pointers to copy of command docstring */
     char *docstr_start, *docstr;
   };
-
-  extern void set_lexer_string (yyscan_t *scn, const char *string);
-  extern void cleanup_lexer (yyscan_t *scn);
-}
-
-/* functionality this unit exports */
-%code provides {
-  /* maximum length of a number, lexer will not match anything longer */
-  #define DECIMAL_STRLEN_MAX 20
-}
-
-/* valid semantic types for tokens and rules */
-%union {
-  long long number;
-  char *string;
-  struct graph_node *node;
-  struct subgraph *subgraph;
 }
 
 /* union types for lexed tokens */