home: hub: minipeg

Download patch

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

imported peg-0.1.6

--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@
 
 ## Version history
 
+* **0.1.6** ([zip](peg/zipball/0.1.6), [tar.gz](peg/tarball/0.1.6)) &mdash; 2011-11-24  
+Allow octal escapes in character classes.
 * **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.  
--- a/compile.c
+++ b/compile.c
@@ -13,7 +13,7 @@
  * 
  * THE SOFTWARE IS PROVIDED 'AS IS'.  USE ENTIRELY AT YOUR OWN RISK.
  * 
- * Last edited: 2011-11-24 09:27:23 by piumarta on emilia
+ * Last edited: 2011-11-24 10:10:20 by piumarta on emilia
  */
 
 #include <stdio.h>
@@ -35,6 +35,41 @@
 
 typedef void (*setter)(unsigned char bits[], int c);
 
+static inline int oigit(int c)	{ return '0' <= c && c <= '7'; }
+
+static int cnext(unsigned char **ccp)
+{
+    unsigned char *cclass= *ccp;
+    int c= *cclass++;
+    if (c)
+    {
+	if ('\\' == c && *cclass)
+	{
+	    switch (c= *cclass++)
+	    {
+		case 'a':  c= '\a'; break;	/* bel */
+		case 'b':  c= '\b'; break;	/* bs */
+		case 'e':  c= '\e'; break;	/* esc */
+		case 'f':  c= '\f'; break;	/* ff */
+		case 'n':  c= '\n'; break;	/* nl */
+		case 'r':  c= '\r'; break;	/* cr */
+		case 't':  c= '\t'; break;	/* ht */
+		case 'v':  c= '\v'; break;	/* vt */
+		default:
+		    if (oigit(c))
+		    {
+			c -= '0';
+			if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0';
+			if (oigit(*cclass)) c= (c << 3) + *cclass++ - '0';
+		    }
+		    break;
+	    }
+	}
+	*ccp= cclass;
+    }
+    return c;
+}
+
 static char *makeCharClass(unsigned char *cclass)
 {
   unsigned char	 bits[32];
@@ -54,32 +89,21 @@
       memset(bits, 0, 32);
       set= charClassSet;
     }
-  while ((c= *cclass++))
+
+  while (*cclass)
     {
-      if ('-' == c && *cclass && prev >= 0)
+      if ('-' == *cclass && cclass[1] && prev >= 0)
 	{
-	  for (c= *cclass++;  prev <= c;  ++prev)
+	  ++cclass;
+	  for (c= cnext(&cclass);  prev <= c;  ++prev)
 	    set(bits, prev);
 	  prev= -1;
 	}
-      else if ('\\' == c && *cclass)
+      else
 	{
-	  switch (c= *cclass++)
-	    {
-	    case 'a':  c= '\a'; break;	/* bel */
-	    case 'b':  c= '\b'; break;	/* bs */
-	    case 'e':  c= '\e'; break;	/* esc */
-	    case 'f':  c= '\f'; break;	/* ff */
-	    case 'n':  c= '\n'; break;	/* nl */
-	    case 'r':  c= '\r'; break;	/* cr */
-	    case 't':  c= '\t'; break;	/* ht */
-	    case 'v':  c= '\v'; break;	/* vt */
-	    default:		break;
-	    }
+	  c= cnext(&cclass);
 	  set(bits, prev= c);
 	}
-      else
-	set(bits, prev= c);
     }
 
   ptr= string;
--- a/peg.peg-c
+++ b/peg.peg-c
@@ -1,4 +1,4 @@
-/* A recursive-descent parser generated by peg 0.1.5 */
+/* A recursive-descent parser generated by peg 0.1.6 */
 
 #include <stdio.h>
 #include <stdlib.h>
--- a/version.h
+++ b/version.h
@@ -1,3 +1,3 @@
 #define PEG_MAJOR	0
 #define PEG_MINOR	1
-#define PEG_LEVEL	5
+#define PEG_LEVEL	6