Skip to content

Commit

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

## Version history

* **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.
Backslash can be escaped.
* **0.1.4** ([zip](peg/zipball/0.1.4), [tar.gz](peg/tarball/0.1.4)) — 2009-08-26
Fix match of a single single quote character.
Rename `getline` -> `nextline` to avoid C namespace conflict.
Expand Down
18 changes: 13 additions & 5 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: 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>
Expand Down Expand Up @@ -120,10 +120,18 @@ static void Node_compile_c_ko(Node *node, int ko)
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;

Expand Down Expand Up @@ -470,7 +478,7 @@ YY_LOCAL(int) yyText(int begin, int end)\n\
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\
Expand Down
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ basic : .FORCE

clean : .FORCE
rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES)
rm -rf *.dSYM

spotless : clean

Expand Down
8 changes: 4 additions & 4 deletions examples/basic.leg
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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))

Expand All @@ -48,7 +48,7 @@
memcpy(buf, linep->text, result); \
} \
else \
result= getline(buf, max_size); \
result= nextline(buf, max_size); \
}

union value {
Expand Down Expand Up @@ -198,7 +198,7 @@ void error(char *fmt, ...)
# include <readline/history.h>
#endif

int getline(char *buf, int max)
int nextline(char *buf, int max)
{
pc= -1;
if (batch) exit(0);
Expand Down
6 changes: 3 additions & 3 deletions leg.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -198,7 +198,7 @@ YY_LOCAL(int) yyText(int begin, int end)
yyleng= 0;
else
{
while (yytextlen < (yyleng - 1))
while (yytextlen < (yyleng + 1))
{
yytextlen *= 2;
yytext= realloc(yytext, yytextlen);
Expand Down Expand Up @@ -483,7 +483,7 @@ YY_RULE(int) yy_range()
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;
Expand Down
4 changes: 2 additions & 2 deletions leg.leg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -111,7 +111,7 @@ class= '[' < ( !']' range )* > ']' -

range= char '-' char | char

char= '\\' [abefnrtv'"\[\]\\]
char= '\\' [-abefnrtv'"\[\]\\]
| '\\' [0-3][0-7][0-7]
| '\\' [0-7][0-7]?
| !'\\' .
Expand Down
9 changes: 5 additions & 4 deletions 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.0 */
/* A recursive-descent parser generated by peg 0.1.5 */

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -73,7 +73,7 @@ YY_VARIABLE(int ) yyvalslen= 0;
YY_LOCAL(int) yyrefill(void)
{
int yyn;
if (yybuflen - yypos < 512)
while (yybuflen - yypos < 512)
{
yybuflen *= 2;
yybuf= realloc(yybuf, yybuflen);
Expand Down Expand Up @@ -138,7 +138,7 @@ YY_LOCAL(int) yymatchClass(unsigned char *bits)

YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
{
if (yythunkpos >= yythunkslen)
while (yythunkpos >= yythunkslen)
{
yythunkslen *= 2;
yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
Expand All @@ -156,7 +156,7 @@ YY_LOCAL(int) yyText(int begin, int end)
yyleng= 0;
else
{
if (yytextlen < (yyleng - 1))
while (yytextlen < (yyleng + 1))
{
yytextlen *= 2;
yytext= realloc(yytext, yytextlen);
Expand Down Expand Up @@ -790,6 +790,7 @@ YY_PARSE(int) YYPARSEFROM(yyrule yystart)
(void)yyPush;
(void)yyPop;
(void)yySet;
(void)yytextmax;
}

YY_PARSE(int) YYPARSE(void)
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 2
#define PEG_LEVEL 5

0 comments on commit d151099

Please sign in to comment.