home: hub: minipeg

Download patch

ref: 8a4dff20506f207ad79b61381cdd7bda01f95c4c
parent: 6e9837bf805098bb675df61fb7246f292c8fc6ea
author: Gregory Pakosz <gregory.pakosz@gmail.com>
date: Wed Nov 23 18:00:00 CST 2011

imported peg-0.1.5

--- a/README.md
+++ b/README.md
@@ -26,6 +26,10 @@
 
 ## Version history
 
+* **0.1.5** ([zip](peg/zipball/0.1.5), [tar.gz](peg/tarball/0.1.5)) &mdash; 2011-11-24  
+Remove dwarf sym dirs when cleaning.  
+Fix size calculation when resizing text buffers.  
+Backslash can be escaped.  
 * **0.1.4** ([zip](peg/zipball/0.1.4), [tar.gz](peg/tarball/0.1.4)) &mdash; 2009-08-26  
 Fix match of a single single quote character.  
 Rename `getline` -> `nextline` to avoid C namespace conflict.  
--- a/compile.c
+++ b/compile.c
@@ -13,7 +13,7 @@
  * 
  * THE SOFTWARE IS PROVIDED 'AS IS'.  USE ENTIRELY AT YOUR OWN RISK.
  * 
- * Last edited: 2007-08-31 13:55:23 by piumarta on emilia.local
+ * Last edited: 2011-11-24 09:27:23 by piumarta on emilia
  */
 
 #include <stdio.h>
@@ -120,10 +120,18 @@
     case String:
       {
 	int len= strlen(node->string.value);
-	if (1 == len || (2 == len && '\\' == node->string.value[0]))
-	  fprintf(output, "  if (!yymatchChar('%s')) goto l%d;", node->string.value, ko);
+	if (1 == len)
+	  {
+	    if ('\'' == node->string.value[0])
+	      fprintf(output, "  if (!yymatchChar('\\'')) goto l%d;", ko);
+	    else
+	      fprintf(output, "  if (!yymatchChar('%s')) goto l%d;", node->string.value, ko);
+	  }
 	else
-	  fprintf(output, "  if (!yymatchString(\"%s\")) goto l%d;", node->string.value, ko);
+	  if (2 == len && '\\' == node->string.value[0])
+	    fprintf(output, "  if (!yymatchChar('%s')) goto l%d;", node->string.value, ko);
+	  else 
+	    fprintf(output, "  if (!yymatchString(\"%s\")) goto l%d;", node->string.value, ko);
       }
       break;
 
@@ -470,7 +478,7 @@
     yyleng= 0;\n\
   else\n\
     {\n\
-      while (yytextlen < (yyleng - 1))\n\
+      while (yytextlen < (yyleng + 1))\n\
 	{\n\
 	  yytextlen *= 2;\n\
 	  yytext= realloc(yytext, yytextlen);\n\
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -73,6 +73,7 @@
 
 clean : .FORCE
 	rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES)
+	rm -rf *.dSYM
 
 spotless : clean
 
--- a/examples/basic.leg
+++ b/examples/basic.leg
@@ -16,7 +16,7 @@
 # 
 # THE SOFTWARE IS PROVIDED 'AS IS'.  USE ENTIRELY AT YOUR OWN RISK.
 # 
-# Last edited: 2007-05-14 11:32:49 by piumarta on emilia
+# Last edited: 2009-10-26 14:04:30 by piumarta on ubuntu2
 
 %{
 # include <stdio.h>
@@ -35,7 +35,7 @@
   int   pc= -1, epc= -1;
   int   batch= 0;
 
-  int getline(char *buf, int max);
+  int nextline(char *buf, int max);
 
 # define min(x, y) ((x) < (y) ? (x) : (y))
 
@@ -48,7 +48,7 @@
         memcpy(buf, linep->text, result);	\
       }						\
     else					\
-      result= getline(buf, max_size);		\
+      result= nextline(buf, max_size);		\
   }
 
   union value {
@@ -198,7 +198,7 @@
 # include <readline/history.h>
 #endif
 
-int getline(char *buf, int max)
+int nextline(char *buf, int max)
 {
   pc= -1;
   if (batch) exit(0);
--- a/leg.c
+++ b/leg.c
@@ -1,4 +1,4 @@
-/* A recursive-descent parser generated by peg 0.1.1 */
+/* A recursive-descent parser generated by peg 0.1.4 */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -198,7 +198,7 @@
     yyleng= 0;
   else
     {
-      while (yytextlen < (yyleng - 1))
+      while (yytextlen < (yyleng + 1))
 	{
 	  yytextlen *= 2;
 	  yytext= realloc(yytext, yytextlen);
@@ -483,7 +483,7 @@
 YY_RULE(int) yy_char()
 {  int yypos0= yypos, yythunkpos0= yythunkpos;
   yyprintf((stderr, "%s\n", "char"));
-  {  int yypos24= yypos, yythunkpos24= yythunkpos;  if (!yymatchChar('\\')) goto l25;  if (!yymatchClass((unsigned char *)"\000\000\000\000\204\000\000\000\000\000\000\070\146\100\124\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l25;  goto l24;
+  {  int yypos24= yypos, yythunkpos24= yythunkpos;  if (!yymatchChar('\\')) goto l25;  if (!yymatchClass((unsigned char *)"\000\000\000\000\204\040\000\000\000\000\000\070\146\100\124\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l25;  goto l24;
   l25:;	  yypos= yypos24; yythunkpos= yythunkpos24;  if (!yymatchChar('\\')) goto l26;  if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\017\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l26;  if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l26;  if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l26;  goto l24;
   l26:;	  yypos= yypos24; yythunkpos= yythunkpos24;  if (!yymatchChar('\\')) goto l27;  if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l27;
   {  int yypos28= yypos, yythunkpos28= yythunkpos;  if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l28;  goto l29;
--- a/leg.leg
+++ b/leg.leg
@@ -15,7 +15,7 @@
 # 
 # THE SOFTWARE IS PROVIDED 'AS IS'.  USE ENTIRELY AT YOUR OWN RISK.
 # 
-# Last edited: 2007-09-13 08:12:17 by piumarta on emilia.local
+# Last edited: 2011-11-24 09:27:56 by piumarta on emilia
 
 %{
 # include "tree.h"
@@ -111,7 +111,7 @@
 
 range=		char '-' char | char
 
-char=		'\\' [abefnrtv'"\[\]\\]
+char=		'\\' [-abefnrtv'"\[\]\\]
 |		'\\' [0-3][0-7][0-7]
 |		'\\' [0-7][0-7]?
 |		!'\\' .
--- a/peg.peg-c
+++ b/peg.peg-c
@@ -1,4 +1,4 @@
-/* A recursive-descent parser generated by peg 0.1.0 */
+/* A recursive-descent parser generated by peg 0.1.5 */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -73,7 +73,7 @@
 YY_LOCAL(int) yyrefill(void)
 {
   int yyn;
-  if (yybuflen - yypos < 512)
+  while (yybuflen - yypos < 512)
     {
       yybuflen *= 2;
       yybuf= realloc(yybuf, yybuflen);
@@ -138,7 +138,7 @@
 
 YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
 {
-  if (yythunkpos >= yythunkslen)
+  while (yythunkpos >= yythunkslen)
     {
       yythunkslen *= 2;
       yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
@@ -156,7 +156,7 @@
     yyleng= 0;
   else
     {
-      if (yytextlen < (yyleng - 1))
+      while (yytextlen < (yyleng + 1))
 	{
 	  yytextlen *= 2;
 	  yytext= realloc(yytext, yytextlen);
@@ -790,6 +790,7 @@
   (void)yyPush;
   (void)yyPop;
   (void)yySet;
+  (void)yytextmax;
 }
 
 YY_PARSE(int) YYPARSE(void)
--- a/version.h
+++ b/version.h
@@ -1,3 +1,3 @@
 #define PEG_MAJOR	0
 #define PEG_MINOR	1
-#define PEG_LEVEL	2
+#define PEG_LEVEL	5