home: hub: minipeg

Download patch

ref: 73492bd20d42c69e5f5cb0df12d5cf06e8f57374
parent: 43e436fe16dc8e3d18e15c03be8ff32124ff0f94
author: Andrew Chambers <ac@acha.ninja>
date: Tue Aug 9 08:35:17 CDT 2022

Improvements to portability from noam.

--- a/Makefile
+++ b/Makefile
@@ -10,12 +10,15 @@
 
 all: minipeg
 
-install: $(BINDIR) $(BINDIR)/leg $(MANDIR) $(MANDIR)/peg.1
-	mkdir -p $(MANDIR) $(BINDIR)
-	cp minipeg $(BINDIR)
-	cp doc/minipeg.1 $(MANDIR)
+install: $(BINDIR)/minipeg $(MANDIR)/minipeg.1
 
-$(MANDIR) :
+$(BINDIR)/minipeg: minipeg
+	cp $< $@
+
+$(MANDIR)/minipeg.1: minipeg.1
+	cp $< $@
+
+$(MANDIR):
 	mkdir -p $(MANDIR)
 
 bootstrap-minipeg: minipeg.c
--- a/compile.c
+++ b/compile.c
@@ -389,7 +389,11 @@
 
 static char *preamble= "\
 #ifndef YY_MAYBE_UNUSED\n\
+#ifdef __GNUC__\n\
 #define YY_MAYBE_UNUSED __attribute__((unused))\n\
+#else\n\
+#define YY_MAYBE_UNUSED\n\
+#endif\n\
 #endif\n\
 #ifndef YY_MALLOC\n\
 #define YY_MALLOC(C, N)		malloc(N)\n\
--- a/minipeg.c
+++ b/minipeg.c
@@ -21,13 +21,12 @@
 
 */
 #include <assert.h>
-#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #line 1 "version.h"
-#define MINIPEG_VERSION "4e9111b"
+#define MINIPEG_VERSION "77a5ec7b"
 #line 1 "tree.h"
 
 enum { Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Inline, Predicate, Error, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus };
@@ -510,8 +509,12 @@
 
 static char *preamble= "\
 #ifndef YY_MAYBE_UNUSED\n\
+#ifdef __GNUC__\n\
 #define YY_MAYBE_UNUSED __attribute__((unused))\n\
+#else\n\
+#define YY_MAYBE_UNUSED\n\
 #endif\n\
+#endif\n\
 #ifndef YY_MALLOC\n\
 #define YY_MALLOC(C, N)		malloc(N)\n\
 #endif\n\
@@ -1273,7 +1276,7 @@
 
 void Rule_print(Node *node)	{ Rule_fprint(stderr, node); }
 #line 1 "peg.c"
-/* Parser generated by minipeg 4e9111b */
+/* Parser generated by minipeg 77a5ec7b */
 
 #define YYRULECOUNT 38
 typedef struct _yycontext yycontext;
@@ -1317,8 +1320,12 @@
 # define YY_RULE(T)	static T
 
 #ifndef YY_MAYBE_UNUSED
+#ifdef __GNUC__
 #define YY_MAYBE_UNUSED __attribute__((unused))
+#else
+#define YY_MAYBE_UNUSED
 #endif
+#endif
 #ifndef YY_MALLOC
 #define YY_MALLOC(C, N)		malloc(N)
 #endif
@@ -1632,7 +1639,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_end_of_line\n"));
   {
-#line 138
+#line 137
    ++lineNumber ;
   }
 #undef yythunkpos
@@ -1645,7 +1652,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_action\n"));
   {
-#line 112
+#line 111
    actionLine= lineNumber ;
   }
 #undef yythunkpos
@@ -1658,7 +1665,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_9_primary\n"));
   {
-#line 92
+#line 91
    push(makePredicate("YY_END")); ;
   }
 #undef yythunkpos
@@ -1671,7 +1678,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_8_primary\n"));
   {
-#line 91
+#line 90
    push(makePredicate("YY_BEGIN")); ;
   }
 #undef yythunkpos
@@ -1684,7 +1691,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_7_primary\n"));
   {
-#line 90
+#line 89
    push(makeAction(actionLine, yytext)); ;
   }
 #undef yythunkpos
@@ -1697,7 +1704,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_6_primary\n"));
   {
-#line 89
+#line 88
    push(makeDot()); ;
   }
 #undef yythunkpos
@@ -1710,7 +1717,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_5_primary\n"));
   {
-#line 88
+#line 87
    push(makeClass(yytext)); ;
   }
 #undef yythunkpos
@@ -1723,7 +1730,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_4_primary\n"));
   {
-#line 87
+#line 86
    push(makeString(yytext)); ;
   }
 #undef yythunkpos
@@ -1736,7 +1743,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_3_primary\n"));
   {
-#line 85
+#line 84
    push(makeName(findRule(yytext))); ;
   }
 #undef yythunkpos
@@ -1749,7 +1756,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_primary\n"));
   {
-#line 84
+#line 83
    Node *name= makeName(findRule(yytext));  name->name.variable= pop();  push(name); ;
   }
 #undef yythunkpos
@@ -1762,7 +1769,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_primary\n"));
   {
-#line 83
+#line 82
    push(makeVariable(yytext)); ;
   }
 #undef yythunkpos
@@ -1775,7 +1782,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_3_suffix\n"));
   {
-#line 80
+#line 79
    push(makePlus (pop())); ;
   }
 #undef yythunkpos
@@ -1788,7 +1795,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_suffix\n"));
   {
-#line 79
+#line 78
    push(makeStar (pop())); ;
   }
 #undef yythunkpos
@@ -1801,7 +1808,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_suffix\n"));
   {
-#line 78
+#line 77
    push(makeQuery(pop())); ;
   }
 #undef yythunkpos
@@ -1814,7 +1821,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_4_prefix\n"));
   {
-#line 75
+#line 74
    push(makePeekNot(pop())); ;
   }
 #undef yythunkpos
@@ -1827,7 +1834,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_3_prefix\n"));
   {
-#line 74
+#line 73
    push(makePeekFor(pop())); ;
   }
 #undef yythunkpos
@@ -1840,7 +1847,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_prefix\n"));
   {
-#line 73
+#line 72
    push(makePredicate(yytext)); ;
   }
 #undef yythunkpos
@@ -1853,7 +1860,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_prefix\n"));
   {
-#line 72
+#line 71
    push(makeInline(yytext)); ;
   }
 #undef yythunkpos
@@ -1866,7 +1873,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_error\n"));
   {
-#line 69
+#line 68
    push(makeError(pop(), yytext)); ;
   }
 #undef yythunkpos
@@ -1879,7 +1886,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_sequence\n"));
   {
-#line 66
+#line 65
    Node *f= pop();  push(Sequence_append(pop(), f)); ;
   }
 #undef yythunkpos
@@ -1892,7 +1899,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_expression\n"));
   {
-#line 63
+#line 62
    Node *f= pop();  push(Alternate_append(pop(), f)); ;
   }
 #undef yythunkpos
@@ -1905,7 +1912,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_definition\n"));
   {
-#line 61
+#line 60
    Node *e= pop();  Rule_setExpression(pop(), e); ;
   }
 #undef yythunkpos
@@ -1918,7 +1925,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_definition\n"));
   {
-#line 59
+#line 58
    if (push(beginRule(findRule(yytext)))->rule.expression)
 							    fprintf(stderr, "rule '%s' redefined\n", yytext); ;
   }
@@ -1932,7 +1939,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_trailer\n"));
   {
-#line 57
+#line 56
    makeTrailer(headerLine, yytext); ;
   }
 #undef yythunkpos
@@ -1945,7 +1952,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_trailer\n"));
   {
-#line 56
+#line 55
    headerLine= lineNumber ;
   }
 #undef yythunkpos
@@ -1958,7 +1965,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_2_declaration\n"));
   {
-#line 54
+#line 53
    makeHeader(headerLine, yytext); ;
   }
 #undef yythunkpos
@@ -1971,7 +1978,7 @@
 #define yythunkpos yy->__thunkpos
   yyprintf((stderr, "do yy_1_declaration\n"));
   {
-#line 52
+#line 51
    headerLine= lineNumber; ;
   }
 #undef yythunkpos
@@ -2620,7 +2627,7 @@
 }
 
 #endif
-#line 141 "peg.peg"
+#line 140 "peg.peg"
 
 
 void yyerror(char *message)
@@ -2698,11 +2705,11 @@
       switch (c)
 	{
 	case 'V':
-	  version(basename(argv[0]));
+	  version(argv[0]);
 	  exit(0);
 
 	case 'h':
-	  usage(basename(argv[0]));
+	  usage(argv[0]);
 	  break;
 
 	case 'o':
--- a/peg.peg
+++ b/peg.peg
@@ -6,7 +6,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <libgen.h>
 #include <assert.h>
 
   typedef struct Header Header;
@@ -215,11 +214,11 @@
       switch (c)
 	{
 	case 'V':
-	  version(basename(argv[0]));
+	  version(argv[0]);
 	  exit(0);
 
 	case 'h':
-	  usage(basename(argv[0]));
+	  usage(argv[0]);
 	  break;
 
 	case 'o':