Skip to content

Commit

Permalink
imported peg-0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gpakosz committed Nov 23, 2011
1 parent d151099 commit 889ac45
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ distribute them any way you like.

## Version history

* **0.1.6** ([zip](peg/zipball/0.1.6), [tar.gz](peg/tarball/0.1.6)) — 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)) — 2011-11-24
Remove dwarf sym dirs when cleaning.
Fix size calculation when resizing text buffers.
Expand Down
62 changes: 43 additions & 19 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -35,6 +35,41 @@ static void charClassClear(unsigned char bits[], int c) { bits[c >> 3] &= ~(1 <<

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];
Expand All @@ -54,32 +89,21 @@ static char *makeCharClass(unsigned char *cclass)
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;
Expand Down
2 changes: 1 addition & 1 deletion peg.peg-c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define PEG_MAJOR 0
#define PEG_MINOR 1
#define PEG_LEVEL 5
#define PEG_LEVEL 6

0 comments on commit 889ac45

Please sign in to comment.