ref: 6408369987c4a9ddb1020f0cbc6b85157100d11d
parent: 74bd921fc755aefb20c8171d83758bc3f5d0877b
author: Gregory Pakosz <gregory.pakosz@gmail.com>
date: Fri Jul 8 05:11:25 CDT 2016
imported peg-0.1.16
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-06-25 piumarta <com -dot- gmail -at- piumarta (backwards)>
+
+ * src/version.h: 0.1.16
+
+ * src/tree.[ch], src/compile.c, src/leg.leg: Add @-actions.
+
+ * src/peg.1: Explain @-actions.
+
+ * src/peg/peg-c, src/leg.c: Regenerate C source.
+
2013-12-18 piumarta <com -dot- gmail -at- piumarta (backwards)>
* src/version.h: 0.1.15
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@
## Version history
+* **0.1.16** ([zip](../../archive/0.1.16.zip), [tar.gz](../../archive/0.1.16.tar.gz)) — 2016-06-25
+Add `@{...}` actions that are performed during matching.
* **0.1.15** ([zip](../../archive/0.1.15.zip), [tar.gz](../../archive/0.1.15.tar.gz)) — 2013-12-17
Calls to `YY_FREE` fixed (thanks to Andrew Dunham).
* **0.1.14** ([zip](../../archive/0.1.14.zip), [tar.gz](../../archive/0.1.14.tar.gz)) — 2013-12-01
--- a/src/compile.c
+++ b/src/compile.c
@@ -13,7 +13,7 @@
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*
- * Last edited: 2013-12-18 10:09:42 by piumarta on linux32
+ * Last edited: 2016-02-19 11:08:58 by piumarta on zora
*/
#include <stdio.h>
@@ -186,11 +186,20 @@
fprintf(output, " yyDo(yy, yy%s, yy->__begin, yy->__end);", node->action.name);
break;
+ case Inline:
+ fprintf(output, " yyText(yy, yy->__begin, yy->__end);\n");
+ fprintf(output, "#define yytext yy->__text\n");
+ fprintf(output, "#define yyleng yy->__textlen\n");
+ fprintf(output, "%s;\n", node->inLine.text);
+ fprintf(output, "#undef yytext\n");
+ fprintf(output, "#undef yyleng\n");
+ break;
+
case Predicate:
fprintf(output, " yyText(yy, yy->__begin, yy->__end); {\n");
fprintf(output, "#define yytext yy->__text\n");
fprintf(output, "#define yyleng yy->__textlen\n");
- fprintf(output, "if (!(%s)) goto l%d;\n", node->action.text, ko);
+ fprintf(output, "if (!(%s)) goto l%d;\n", node->predicate.text, ko);
fprintf(output, "#undef yytext\n");
fprintf(output, "#undef yyleng\n");
fprintf(output, " }");
@@ -755,6 +764,7 @@
case String: return strlen(node->string.value) > 0;
case Class: return 1;
case Action: return 0;
+ case Inline: return 0;
case Predicate: return 0;
case Error: return consumesInput(node->error.element);
--- a/src/leg.c
+++ b/src/leg.c
@@ -1,9 +1,9 @@
-/* A recursive-descent parser generated by peg 0.1.15 */
+/* A recursive-descent parser generated by peg 0.1.16 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#define YYRULECOUNT 38
+#define YYRULECOUNT 39
# include "tree.h"
# include "version.h"
@@ -314,27 +314,28 @@
#define YYACCEPT yyAccept(yy, yythunkpos0)
-YY_RULE(int) yy_end_of_line(yycontext *yy); /* 38 */
-YY_RULE(int) yy_comment(yycontext *yy); /* 37 */
-YY_RULE(int) yy_space(yycontext *yy); /* 36 */
-YY_RULE(int) yy_braces(yycontext *yy); /* 35 */
-YY_RULE(int) yy_range(yycontext *yy); /* 34 */
-YY_RULE(int) yy_char(yycontext *yy); /* 33 */
-YY_RULE(int) yy_END(yycontext *yy); /* 32 */
-YY_RULE(int) yy_BEGIN(yycontext *yy); /* 31 */
-YY_RULE(int) yy_DOT(yycontext *yy); /* 30 */
-YY_RULE(int) yy_class(yycontext *yy); /* 29 */
-YY_RULE(int) yy_literal(yycontext *yy); /* 28 */
-YY_RULE(int) yy_CLOSE(yycontext *yy); /* 27 */
-YY_RULE(int) yy_OPEN(yycontext *yy); /* 26 */
-YY_RULE(int) yy_COLON(yycontext *yy); /* 25 */
-YY_RULE(int) yy_PLUS(yycontext *yy); /* 24 */
-YY_RULE(int) yy_STAR(yycontext *yy); /* 23 */
-YY_RULE(int) yy_QUESTION(yycontext *yy); /* 22 */
-YY_RULE(int) yy_primary(yycontext *yy); /* 21 */
-YY_RULE(int) yy_NOT(yycontext *yy); /* 20 */
-YY_RULE(int) yy_suffix(yycontext *yy); /* 19 */
-YY_RULE(int) yy_AND(yycontext *yy); /* 18 */
+YY_RULE(int) yy_end_of_line(yycontext *yy); /* 39 */
+YY_RULE(int) yy_comment(yycontext *yy); /* 38 */
+YY_RULE(int) yy_space(yycontext *yy); /* 37 */
+YY_RULE(int) yy_braces(yycontext *yy); /* 36 */
+YY_RULE(int) yy_range(yycontext *yy); /* 35 */
+YY_RULE(int) yy_char(yycontext *yy); /* 34 */
+YY_RULE(int) yy_END(yycontext *yy); /* 33 */
+YY_RULE(int) yy_BEGIN(yycontext *yy); /* 32 */
+YY_RULE(int) yy_DOT(yycontext *yy); /* 31 */
+YY_RULE(int) yy_class(yycontext *yy); /* 30 */
+YY_RULE(int) yy_literal(yycontext *yy); /* 29 */
+YY_RULE(int) yy_CLOSE(yycontext *yy); /* 28 */
+YY_RULE(int) yy_OPEN(yycontext *yy); /* 27 */
+YY_RULE(int) yy_COLON(yycontext *yy); /* 26 */
+YY_RULE(int) yy_PLUS(yycontext *yy); /* 25 */
+YY_RULE(int) yy_STAR(yycontext *yy); /* 24 */
+YY_RULE(int) yy_QUESTION(yycontext *yy); /* 23 */
+YY_RULE(int) yy_primary(yycontext *yy); /* 22 */
+YY_RULE(int) yy_NOT(yycontext *yy); /* 21 */
+YY_RULE(int) yy_suffix(yycontext *yy); /* 20 */
+YY_RULE(int) yy_AND(yycontext *yy); /* 19 */
+YY_RULE(int) yy_AT(yycontext *yy); /* 18 */
YY_RULE(int) yy_action(yycontext *yy); /* 17 */
YY_RULE(int) yy_TILDE(yycontext *yy); /* 16 */
YY_RULE(int) yy_prefix(yycontext *yy); /* 15 */
@@ -509,6 +510,19 @@
#undef yypos
#undef yy
}
+YY_ACTION(void) yy_4_prefix(yycontext *yy, char *yytext, int yyleng)
+{
+#define __ yy->__
+#define yypos yy->__pos
+#define yythunkpos yy->__thunkpos
+ yyprintf((stderr, "do yy_4_prefix\n"));
+ {
+ push(makePeekNot(pop())); ;
+ }
+#undef yythunkpos
+#undef yypos
+#undef yy
+}
YY_ACTION(void) yy_3_prefix(yycontext *yy, char *yytext, int yyleng)
{
#define __ yy->__
@@ -516,7 +530,7 @@
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_3_prefix\n"));
{
- push(makePeekNot(pop())); ;
+ push(makePeekFor(pop())); ;
}
#undef yythunkpos
#undef yypos
@@ -529,7 +543,7 @@
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_prefix\n"));
{
- push(makePeekFor(pop())); ;
+ push(makePredicate(yytext)); ;
}
#undef yythunkpos
#undef yypos
@@ -542,7 +556,7 @@
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_prefix\n"));
{
- push(makePredicate(yytext)); ;
+ push(makeInline(yytext)); ;
}
#undef yythunkpos
#undef yypos
@@ -964,37 +978,46 @@
yyprintf((stderr, " fail %s @ %s\n", "AND", yy->__buf+yy->__pos));
return 0;
}
+YY_RULE(int) yy_AT(yycontext *yy)
+{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
+ yyprintf((stderr, "%s\n", "AT")); if (!yymatchChar(yy, '@')) goto l74; if (!yy__(yy)) goto l74;
+ yyprintf((stderr, " ok %s @ %s\n", "AT", yy->__buf+yy->__pos));
+ return 1;
+ l74:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ yyprintf((stderr, " fail %s @ %s\n", "AT", yy->__buf+yy->__pos));
+ return 0;
+}
YY_RULE(int) yy_action(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(yy, '{')) goto l74; yyText(yy, yy->__begin, yy->__end); {
+ yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(yy, '{')) goto l75; yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_BEGIN)) goto l74;
+if (!(YY_BEGIN)) goto l75;
#undef yytext
#undef yyleng
}
- l75:;
- { int yypos76= yy->__pos, yythunkpos76= yy->__thunkpos; if (!yy_braces(yy)) goto l76; goto l75;
- l76:; yy->__pos= yypos76; yy->__thunkpos= yythunkpos76;
+ l76:;
+ { int yypos77= yy->__pos, yythunkpos77= yy->__thunkpos; if (!yy_braces(yy)) goto l77; goto l76;
+ l77:; yy->__pos= yypos77; yy->__thunkpos= yythunkpos77;
} yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_END)) goto l74;
+if (!(YY_END)) goto l75;
#undef yytext
#undef yyleng
- } if (!yymatchChar(yy, '}')) goto l74; if (!yy__(yy)) goto l74;
+ } if (!yymatchChar(yy, '}')) goto l75; if (!yy__(yy)) goto l75;
yyprintf((stderr, " ok %s @ %s\n", "action", yy->__buf+yy->__pos));
return 1;
- l74:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l75:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "action", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_TILDE(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "TILDE")); if (!yymatchChar(yy, '~')) goto l77; if (!yy__(yy)) goto l77;
+ yyprintf((stderr, "%s\n", "TILDE")); if (!yymatchChar(yy, '~')) goto l78; if (!yy__(yy)) goto l78;
yyprintf((stderr, " ok %s @ %s\n", "TILDE", yy->__buf+yy->__pos));
return 1;
- l77:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l78:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "TILDE", yy->__buf+yy->__pos));
return 0;
}
@@ -1001,81 +1024,82 @@
YY_RULE(int) yy_prefix(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
yyprintf((stderr, "%s\n", "prefix"));
- { int yypos79= yy->__pos, yythunkpos79= yy->__thunkpos; if (!yy_AND(yy)) goto l80; if (!yy_action(yy)) goto l80; yyDo(yy, yy_1_prefix, yy->__begin, yy->__end); goto l79;
- l80:; yy->__pos= yypos79; yy->__thunkpos= yythunkpos79; if (!yy_AND(yy)) goto l81; if (!yy_suffix(yy)) goto l81; yyDo(yy, yy_2_prefix, yy->__begin, yy->__end); goto l79;
- l81:; yy->__pos= yypos79; yy->__thunkpos= yythunkpos79; if (!yy_NOT(yy)) goto l82; if (!yy_suffix(yy)) goto l82; yyDo(yy, yy_3_prefix, yy->__begin, yy->__end); goto l79;
- l82:; yy->__pos= yypos79; yy->__thunkpos= yythunkpos79; if (!yy_suffix(yy)) goto l78;
+ { int yypos80= yy->__pos, yythunkpos80= yy->__thunkpos; if (!yy_AT(yy)) goto l81; if (!yy_action(yy)) goto l81; yyDo(yy, yy_1_prefix, yy->__begin, yy->__end); goto l80;
+ l81:; yy->__pos= yypos80; yy->__thunkpos= yythunkpos80; if (!yy_AND(yy)) goto l82; if (!yy_action(yy)) goto l82; yyDo(yy, yy_2_prefix, yy->__begin, yy->__end); goto l80;
+ l82:; yy->__pos= yypos80; yy->__thunkpos= yythunkpos80; if (!yy_AND(yy)) goto l83; if (!yy_suffix(yy)) goto l83; yyDo(yy, yy_3_prefix, yy->__begin, yy->__end); goto l80;
+ l83:; yy->__pos= yypos80; yy->__thunkpos= yythunkpos80; if (!yy_NOT(yy)) goto l84; if (!yy_suffix(yy)) goto l84; yyDo(yy, yy_4_prefix, yy->__begin, yy->__end); goto l80;
+ l84:; yy->__pos= yypos80; yy->__thunkpos= yythunkpos80; if (!yy_suffix(yy)) goto l79;
}
- l79:;
+ l80:;
yyprintf((stderr, " ok %s @ %s\n", "prefix", yy->__buf+yy->__pos));
return 1;
- l78:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l79:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "prefix", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_error(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "error")); if (!yy_prefix(yy)) goto l83;
- { int yypos84= yy->__pos, yythunkpos84= yy->__thunkpos; if (!yy_TILDE(yy)) goto l84; if (!yy_action(yy)) goto l84; yyDo(yy, yy_1_error, yy->__begin, yy->__end); goto l85;
- l84:; yy->__pos= yypos84; yy->__thunkpos= yythunkpos84;
+ yyprintf((stderr, "%s\n", "error")); if (!yy_prefix(yy)) goto l85;
+ { int yypos86= yy->__pos, yythunkpos86= yy->__thunkpos; if (!yy_TILDE(yy)) goto l86; if (!yy_action(yy)) goto l86; yyDo(yy, yy_1_error, yy->__begin, yy->__end); goto l87;
+ l86:; yy->__pos= yypos86; yy->__thunkpos= yythunkpos86;
}
- l85:;
+ l87:;
yyprintf((stderr, " ok %s @ %s\n", "error", yy->__buf+yy->__pos));
return 1;
- l83:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l85:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "error", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_BAR(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "BAR")); if (!yymatchChar(yy, '|')) goto l86; if (!yy__(yy)) goto l86;
+ yyprintf((stderr, "%s\n", "BAR")); if (!yymatchChar(yy, '|')) goto l88; if (!yy__(yy)) goto l88;
yyprintf((stderr, " ok %s @ %s\n", "BAR", yy->__buf+yy->__pos));
return 1;
- l86:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l88:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "BAR", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_sequence(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "sequence")); if (!yy_error(yy)) goto l87;
- l88:;
- { int yypos89= yy->__pos, yythunkpos89= yy->__thunkpos; if (!yy_error(yy)) goto l89; yyDo(yy, yy_1_sequence, yy->__begin, yy->__end); goto l88;
- l89:; yy->__pos= yypos89; yy->__thunkpos= yythunkpos89;
+ yyprintf((stderr, "%s\n", "sequence")); if (!yy_error(yy)) goto l89;
+ l90:;
+ { int yypos91= yy->__pos, yythunkpos91= yy->__thunkpos; if (!yy_error(yy)) goto l91; yyDo(yy, yy_1_sequence, yy->__begin, yy->__end); goto l90;
+ l91:; yy->__pos= yypos91; yy->__thunkpos= yythunkpos91;
}
yyprintf((stderr, " ok %s @ %s\n", "sequence", yy->__buf+yy->__pos));
return 1;
- l87:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l89:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "sequence", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_SEMICOLON(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(yy, ';')) goto l90; if (!yy__(yy)) goto l90;
+ yyprintf((stderr, "%s\n", "SEMICOLON")); if (!yymatchChar(yy, ';')) goto l92; if (!yy__(yy)) goto l92;
yyprintf((stderr, " ok %s @ %s\n", "SEMICOLON", yy->__buf+yy->__pos));
return 1;
- l90:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l92:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "SEMICOLON", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_expression(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "expression")); if (!yy_sequence(yy)) goto l91;
- l92:;
- { int yypos93= yy->__pos, yythunkpos93= yy->__thunkpos; if (!yy_BAR(yy)) goto l93; if (!yy_sequence(yy)) goto l93; yyDo(yy, yy_1_expression, yy->__begin, yy->__end); goto l92;
- l93:; yy->__pos= yypos93; yy->__thunkpos= yythunkpos93;
+ yyprintf((stderr, "%s\n", "expression")); if (!yy_sequence(yy)) goto l93;
+ l94:;
+ { int yypos95= yy->__pos, yythunkpos95= yy->__thunkpos; if (!yy_BAR(yy)) goto l95; if (!yy_sequence(yy)) goto l95; yyDo(yy, yy_1_expression, yy->__begin, yy->__end); goto l94;
+ l95:; yy->__pos= yypos95; yy->__thunkpos= yythunkpos95;
}
yyprintf((stderr, " ok %s @ %s\n", "expression", yy->__buf+yy->__pos));
return 1;
- l91:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l93:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "expression", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_EQUAL(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar(yy, '=')) goto l94; if (!yy__(yy)) goto l94;
+ yyprintf((stderr, "%s\n", "EQUAL")); if (!yymatchChar(yy, '=')) goto l96; if (!yy__(yy)) goto l96;
yyprintf((stderr, " ok %s @ %s\n", "EQUAL", yy->__buf+yy->__pos));
return 1;
- l94:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l96:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "EQUAL", yy->__buf+yy->__pos));
return 0;
}
@@ -1084,32 +1108,32 @@
yyprintf((stderr, "%s\n", "identifier")); yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_BEGIN)) goto l95;
+if (!(YY_BEGIN)) goto l97;
#undef yytext
#undef yyleng
- } if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\040\000\000\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l95;
- l96:;
- { int yypos97= yy->__pos, yythunkpos97= yy->__thunkpos; if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\040\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l97; goto l96;
- l97:; yy->__pos= yypos97; yy->__thunkpos= yythunkpos97;
+ } if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\040\000\000\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l97;
+ l98:;
+ { int yypos99= yy->__pos, yythunkpos99= yy->__thunkpos; if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\040\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l99; goto l98;
+ l99:; yy->__pos= yypos99; yy->__thunkpos= yythunkpos99;
} yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_END)) goto l95;
+if (!(YY_END)) goto l97;
#undef yytext
#undef yyleng
- } if (!yy__(yy)) goto l95;
+ } if (!yy__(yy)) goto l97;
yyprintf((stderr, " ok %s @ %s\n", "identifier", yy->__buf+yy->__pos));
return 1;
- l95:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l97:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "identifier", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_RPERCENT(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "RPERCENT")); if (!yymatchString(yy, "%}")) goto l98; if (!yy__(yy)) goto l98;
+ yyprintf((stderr, "%s\n", "RPERCENT")); if (!yymatchString(yy, "%}")) goto l100; if (!yy__(yy)) goto l100;
yyprintf((stderr, " ok %s @ %s\n", "RPERCENT", yy->__buf+yy->__pos));
return 1;
- l98:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l100:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "RPERCENT", yy->__buf+yy->__pos));
return 0;
}
@@ -1116,78 +1140,78 @@
YY_RULE(int) yy_end_of_file(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
yyprintf((stderr, "%s\n", "end_of_file"));
- { int yypos100= yy->__pos, yythunkpos100= yy->__thunkpos; if (!yymatchDot(yy)) goto l100; goto l99;
- l100:; yy->__pos= yypos100; yy->__thunkpos= yythunkpos100;
+ { int yypos102= yy->__pos, yythunkpos102= yy->__thunkpos; if (!yymatchDot(yy)) goto l102; goto l101;
+ l102:; yy->__pos= yypos102; yy->__thunkpos= yythunkpos102;
}
yyprintf((stderr, " ok %s @ %s\n", "end_of_file", yy->__buf+yy->__pos));
return 1;
- l99:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l101:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "end_of_file", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_trailer(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "trailer")); if (!yymatchString(yy, "%%")) goto l101; yyText(yy, yy->__begin, yy->__end); {
+ yyprintf((stderr, "%s\n", "trailer")); if (!yymatchString(yy, "%%")) goto l103; yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_BEGIN)) goto l101;
+if (!(YY_BEGIN)) goto l103;
#undef yytext
#undef yyleng
}
- l102:;
- { int yypos103= yy->__pos, yythunkpos103= yy->__thunkpos; if (!yymatchDot(yy)) goto l103; goto l102;
- l103:; yy->__pos= yypos103; yy->__thunkpos= yythunkpos103;
+ l104:;
+ { int yypos105= yy->__pos, yythunkpos105= yy->__thunkpos; if (!yymatchDot(yy)) goto l105; goto l104;
+ l105:; yy->__pos= yypos105; yy->__thunkpos= yythunkpos105;
} yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_END)) goto l101;
+if (!(YY_END)) goto l103;
#undef yytext
#undef yyleng
} yyDo(yy, yy_1_trailer, yy->__begin, yy->__end);
yyprintf((stderr, " ok %s @ %s\n", "trailer", yy->__buf+yy->__pos));
return 1;
- l101:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l103:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "trailer", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_definition(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "definition")); if (!yy_identifier(yy)) goto l104; yyDo(yy, yy_1_definition, yy->__begin, yy->__end); if (!yy_EQUAL(yy)) goto l104; if (!yy_expression(yy)) goto l104; yyDo(yy, yy_2_definition, yy->__begin, yy->__end);
- { int yypos105= yy->__pos, yythunkpos105= yy->__thunkpos; if (!yy_SEMICOLON(yy)) goto l105; goto l106;
- l105:; yy->__pos= yypos105; yy->__thunkpos= yythunkpos105;
+ yyprintf((stderr, "%s\n", "definition")); if (!yy_identifier(yy)) goto l106; yyDo(yy, yy_1_definition, yy->__begin, yy->__end); if (!yy_EQUAL(yy)) goto l106; if (!yy_expression(yy)) goto l106; yyDo(yy, yy_2_definition, yy->__begin, yy->__end);
+ { int yypos107= yy->__pos, yythunkpos107= yy->__thunkpos; if (!yy_SEMICOLON(yy)) goto l107; goto l108;
+ l107:; yy->__pos= yypos107; yy->__thunkpos= yythunkpos107;
}
- l106:;
+ l108:;
yyprintf((stderr, " ok %s @ %s\n", "definition", yy->__buf+yy->__pos));
return 1;
- l104:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l106:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "definition", yy->__buf+yy->__pos));
return 0;
}
YY_RULE(int) yy_declaration(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "declaration")); if (!yymatchString(yy, "%{")) goto l107; yyText(yy, yy->__begin, yy->__end); {
+ yyprintf((stderr, "%s\n", "declaration")); if (!yymatchString(yy, "%{")) goto l109; yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_BEGIN)) goto l107;
+if (!(YY_BEGIN)) goto l109;
#undef yytext
#undef yyleng
}
- l108:;
- { int yypos109= yy->__pos, yythunkpos109= yy->__thunkpos;
- { int yypos110= yy->__pos, yythunkpos110= yy->__thunkpos; if (!yymatchString(yy, "%}")) goto l110; goto l109;
- l110:; yy->__pos= yypos110; yy->__thunkpos= yythunkpos110;
- } if (!yymatchDot(yy)) goto l109; goto l108;
- l109:; yy->__pos= yypos109; yy->__thunkpos= yythunkpos109;
+ l110:;
+ { int yypos111= yy->__pos, yythunkpos111= yy->__thunkpos;
+ { int yypos112= yy->__pos, yythunkpos112= yy->__thunkpos; if (!yymatchString(yy, "%}")) goto l112; goto l111;
+ l112:; yy->__pos= yypos112; yy->__thunkpos= yythunkpos112;
+ } if (!yymatchDot(yy)) goto l111; goto l110;
+ l111:; yy->__pos= yypos111; yy->__thunkpos= yythunkpos111;
} yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
-if (!(YY_END)) goto l107;
+if (!(YY_END)) goto l109;
#undef yytext
#undef yyleng
- } if (!yy_RPERCENT(yy)) goto l107; yyDo(yy, yy_1_declaration, yy->__begin, yy->__end);
+ } if (!yy_RPERCENT(yy)) goto l109; yyDo(yy, yy_1_declaration, yy->__begin, yy->__end);
yyprintf((stderr, " ok %s @ %s\n", "declaration", yy->__buf+yy->__pos));
return 1;
- l107:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l109:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "declaration", yy->__buf+yy->__pos));
return 0;
}
@@ -1194,13 +1218,13 @@
YY_RULE(int) yy__(yycontext *yy)
{
yyprintf((stderr, "%s\n", "_"));
- l112:;
- { int yypos113= yy->__pos, yythunkpos113= yy->__thunkpos;
- { int yypos114= yy->__pos, yythunkpos114= yy->__thunkpos; if (!yy_space(yy)) goto l115; goto l114;
- l115:; yy->__pos= yypos114; yy->__thunkpos= yythunkpos114; if (!yy_comment(yy)) goto l113;
+ l114:;
+ { int yypos115= yy->__pos, yythunkpos115= yy->__thunkpos;
+ { int yypos116= yy->__pos, yythunkpos116= yy->__thunkpos; if (!yy_space(yy)) goto l117; goto l116;
+ l117:; yy->__pos= yypos116; yy->__thunkpos= yythunkpos116; if (!yy_comment(yy)) goto l115;
}
- l114:; goto l112;
- l113:; yy->__pos= yypos113; yy->__thunkpos= yythunkpos113;
+ l116:; goto l114;
+ l115:; yy->__pos= yypos115; yy->__thunkpos= yythunkpos115;
}
yyprintf((stderr, " ok %s @ %s\n", "_", yy->__buf+yy->__pos));
return 1;
@@ -1207,26 +1231,26 @@
}
YY_RULE(int) yy_grammar(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
- yyprintf((stderr, "%s\n", "grammar")); if (!yy__(yy)) goto l116;
- { int yypos119= yy->__pos, yythunkpos119= yy->__thunkpos; if (!yy_declaration(yy)) goto l120; goto l119;
- l120:; yy->__pos= yypos119; yy->__thunkpos= yythunkpos119; if (!yy_definition(yy)) goto l116;
- }
- l119:;
- l117:;
- { int yypos118= yy->__pos, yythunkpos118= yy->__thunkpos;
+ yyprintf((stderr, "%s\n", "grammar")); if (!yy__(yy)) goto l118;
{ int yypos121= yy->__pos, yythunkpos121= yy->__thunkpos; if (!yy_declaration(yy)) goto l122; goto l121;
l122:; yy->__pos= yypos121; yy->__thunkpos= yythunkpos121; if (!yy_definition(yy)) goto l118;
}
- l121:; goto l117;
- l118:; yy->__pos= yypos118; yy->__thunkpos= yythunkpos118;
+ l121:;
+ l119:;
+ { int yypos120= yy->__pos, yythunkpos120= yy->__thunkpos;
+ { int yypos123= yy->__pos, yythunkpos123= yy->__thunkpos; if (!yy_declaration(yy)) goto l124; goto l123;
+ l124:; yy->__pos= yypos123; yy->__thunkpos= yythunkpos123; if (!yy_definition(yy)) goto l120;
}
- { int yypos123= yy->__pos, yythunkpos123= yy->__thunkpos; if (!yy_trailer(yy)) goto l123; goto l124;
- l123:; yy->__pos= yypos123; yy->__thunkpos= yythunkpos123;
+ l123:; goto l119;
+ l120:; yy->__pos= yypos120; yy->__thunkpos= yythunkpos120;
}
- l124:; if (!yy_end_of_file(yy)) goto l116;
+ { int yypos125= yy->__pos, yythunkpos125= yy->__thunkpos; if (!yy_trailer(yy)) goto l125; goto l126;
+ l125:; yy->__pos= yypos125; yy->__thunkpos= yythunkpos125;
+ }
+ l126:; if (!yy_end_of_file(yy)) goto l118;
yyprintf((stderr, " ok %s @ %s\n", "grammar", yy->__buf+yy->__pos));
return 1;
- l116:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
+ l118:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "grammar", yy->__buf+yy->__pos));
return 0;
}
--- a/src/leg.leg
+++ b/src/leg.leg
@@ -15,7 +15,7 @@
#
# THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
#
-# Last edited: 2013-08-16 00:14:11 by piumarta on emilia
+# Last edited: 2016-02-19 11:04:51 by piumarta on zora
%{
# include "tree.h"
@@ -82,7 +82,8 @@
error= prefix (TILDE action { push(makeError(pop(), yytext)); }
)?
-prefix= AND action { push(makePredicate(yytext)); }
+prefix= AT action { push(makeInline(yytext)); }
+| AND action { push(makePredicate(yytext)); }
| AND suffix { push(makePeekFor(pop())); }
| NOT suffix { push(makePeekNot(pop())); }
| suffix
@@ -132,6 +133,7 @@
BAR= '|' -
AND= '&' -
NOT= '!' -
+AT= '@' -
QUESTION= '?' -
STAR= '*' -
PLUS= '+' -
--- a/src/peg.1
+++ b/src/peg.1
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2007 by Ian Piumarta
+.\" Copyright (c) 2007,2016 by Ian Piumarta
.\" All rights reserved.
.\"
.\" Permission is hereby granted, free of charge, to any person obtaining a
@@ -13,7 +13,7 @@
.\"
.\" THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
.\"
-.\" Last edited: 2013-09-09 14:58:44 by piumarta on emilia
+.\" Last edited: 2016-06-25 12:38:49 by piumarta on gentoo64.piumarta.com
.\"
.TH PEG 1 "September 2013" "Version 0.1"
.SH NAME
@@ -447,7 +447,7 @@
.TP
.B rule\-name
Hyphens can appear as letters in the names of rules. Each hyphen is
-converted into an underscore in the generated C source code. A single
+converted into an underscore in the generated C source code. A
single hyphen '\-' is a legal rule name.
.nf
@@ -486,6 +486,20 @@
in
.I leg
(with the final semicolon being optional, as described next).
+.TP
+.IB @{\ action\ }
+Actions prefixed with an 'at' symbol will be performed during parsing,
+at the time they are encountered while matching the input text with a
+rule.
+Because of back-tracking in the PEG parsing algorithm, actions
+prefixed with '@' might be performed multiple times for the same input
+text.
+(The usual behviour of actions is that they are saved up until
+matching is complete, and then those that are part of the
+final derivation are performed in left-to-right order.)
+The variable
+.I yytext
+is available within these actions.
.TP
.IB exp \ ~ \ {\ action\ }
A postfix operator
--- a/src/peg.peg-c
+++ b/src/peg.peg-c
@@ -1,4 +1,4 @@
-/* A recursive-descent parser generated by peg 0.1.15 */
+/* A recursive-descent parser generated by peg 0.1.16 */
#include <stdio.h>
#include <stdlib.h>
--- a/src/tree.c
+++ b/src/tree.c
@@ -13,7 +13,7 @@
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*
- * Last edited: 2013-07-20 12:47:35 by piumarta on margaux1
+ * Last edited: 2016-02-19 11:21:30 by piumarta on zora
*/
#include <stdio.h>
@@ -157,6 +157,13 @@
if ('$' == ptr[0] && '$' == ptr[1])
ptr[1]= ptr[0]= '_';
}
+ return node;
+}
+
+Node *makeInline(char *text)
+{
+ Node *node= newNode(Inline);
+ node->inLine.text= strdup(text);
return node;
}
--- a/src/tree.h
+++ b/src/tree.h
@@ -13,12 +13,12 @@
*
* THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
*
- * Last edited: 2012-05-15 22:37:53 by piumarta on emilia
+ * Last edited: 2016-02-19 11:06:20 by piumarta on zora
*/
#include <stdio.h>
-enum { Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Predicate, Error, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus };
+enum { Unknown= 0, Rule, Variable, Name, Dot, Character, String, Class, Action, Inline, Predicate, Error, Alternate, Sequence, PeekFor, PeekNot, Query, Star, Plus };
enum {
RuleUsed = 1<<0,
@@ -35,6 +35,7 @@
struct String { int type; Node *next; char *value; };
struct Class { int type; Node *next; unsigned char *value; };
struct Action { int type; Node *next; char *text; Node *list; char *name; Node *rule; };
+struct Inline { int type; Node *next; char *text; };
struct Predicate { int type; Node *next; char *text; };
struct Error { int type; Node *next; Node *element; char *text; };
struct Alternate { int type; Node *next; Node *first; Node *last; };
@@ -57,6 +58,7 @@
struct String string;
struct Class cclass;
struct Action action;
+ struct Inline inLine;
struct Predicate predicate;
struct Error error;
struct Alternate alternate;
@@ -89,6 +91,7 @@
extern Node *makeString(char *text);
extern Node *makeClass(char *text);
extern Node *makeAction(char *text);
+extern Node *makeInline(char *text);
extern Node *makePredicate(char *text);
extern Node *makeError(Node *e, char *text);
extern Node *makeAlternate(Node *e);
--- a/src/version.h
+++ b/src/version.h
@@ -1,3 +1,3 @@
#define PEG_MAJOR 0
#define PEG_MINOR 1
-#define PEG_LEVEL 15
+#define PEG_LEVEL 16