Skip to content

Commit

Permalink
imported peg-0.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
gpakosz committed Sep 8, 2016
1 parent 25b45a2 commit c8ec83c
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 33 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2016-07-22 Ian Piumarta <com -dot- gmail -at- piumarta (backwards)>

* src/version.h (PEG_LEVEL): Version 0.1.18.
* src/tree.h: Rule_compile_c takes nolines argument for option -P.
* src/compile.c, src/peg.c, src/leg.leg (main): Add option -P.
Generate #line directives for all actions.
* src/peg.1: Document option -P.

2016-07-14 Ian Piumarta <com -dot- gmail -at- piumarta (backwards)>

* src/version.h: 0.1.17
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ distribute them any way you like.

## Version history

* **0.1.18** ([zip](../../archive/0.1.18.zip), [tar.gz](../../archive/0.1.18.tar.gz)) &mdash; 2016-07-22
Add `-P` option to disable `#line` directives.
Emit `#line` directives for all actions.
* **0.1.17** ([zip](../../archive/0.1.17.zip), [tar.gz](../../archive/0.1.17.tar.gz)) &mdash; 2016-07-14
Emit `#line` directives for header and trailer in the generated source file.
* **0.1.16** ([zip](../../archive/0.1.16.zip), [tar.gz](../../archive/0.1.16.tar.gz)) &mdash; 2016-06-25
Expand Down
6 changes: 4 additions & 2 deletions src/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: 2016-02-19 11:08:58 by piumarta on zora
* Last edited: 2016-07-22 09:43:05 by piumarta on zora.local
*/

#include <stdio.h>
Expand Down Expand Up @@ -800,7 +800,7 @@ int consumesInput(Node *node)
}


void Rule_compile_c(Node *node)
void Rule_compile_c(Node *node, int nolines)
{
Node *n;

Expand All @@ -817,6 +817,8 @@ void Rule_compile_c(Node *node)
defineVariables(n->action.rule->rule.variables);
fprintf(output, " yyprintf((stderr, \"do yy%s\\n\"));\n", n->action.name);
fprintf(output, " {\n");
if (!nolines)
fprintf(output, "#line %i\n", n->action.line);
fprintf(output, " %s;\n", n->action.text);
fprintf(output, " }\n");
undefineVariables(n->action.rule->rule.variables);
Expand Down
66 changes: 58 additions & 8 deletions src/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.17 */
/* A recursive-descent parser generated by peg 0.1.18 */

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -27,9 +27,11 @@
FILE *input= 0;

int verboseFlag= 0;
int nolinesFlag= 0;

static int lineNumber= 0;
static int headerLine= 0;
static int actionLine= 0;
static char *fileName= 0;
static int trailerLine= 0;
static char *trailer= 0;
Expand Down Expand Up @@ -365,19 +367,35 @@ YY_ACTION(void) yy_1_end_of_line(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_end_of_line\n"));
{
#line 160
++lineNumber ;
}
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_action(yycontext *yy, char *yytext, int yyleng)
{
#define __ yy->__
#define yypos yy->__pos
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_action\n"));
{
#line 133
actionLine= lineNumber ;
}
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_9_primary(yycontext *yy, char *yytext, int yyleng)
{
#define __ yy->__
#define yypos yy->__pos
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_9_primary\n"));
{
#line 113
push(makePredicate("YY_END")); ;
}
#undef yythunkpos
Expand All @@ -391,6 +409,7 @@ YY_ACTION(void) yy_8_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_8_primary\n"));
{
#line 112
push(makePredicate("YY_BEGIN")); ;
}
#undef yythunkpos
Expand All @@ -404,7 +423,8 @@ YY_ACTION(void) yy_7_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_7_primary\n"));
{
push(makeAction(yytext)); ;
#line 111
push(makeAction(actionLine, yytext)); ;
}
#undef yythunkpos
#undef yypos
Expand All @@ -417,6 +437,7 @@ YY_ACTION(void) yy_6_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_6_primary\n"));
{
#line 110
push(makeDot()); ;
}
#undef yythunkpos
Expand All @@ -430,6 +451,7 @@ YY_ACTION(void) yy_5_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_5_primary\n"));
{
#line 109
push(makeClass(yytext)); ;
}
#undef yythunkpos
Expand All @@ -443,6 +465,7 @@ YY_ACTION(void) yy_4_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_4_primary\n"));
{
#line 108
push(makeString(yytext)); ;
}
#undef yythunkpos
Expand All @@ -456,6 +479,7 @@ YY_ACTION(void) yy_3_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_3_primary\n"));
{
#line 106
push(makeName(findRule(yytext))); ;
}
#undef yythunkpos
Expand All @@ -469,6 +493,7 @@ YY_ACTION(void) yy_2_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_primary\n"));
{
#line 105
Node *name= makeName(findRule(yytext)); name->name.variable= pop(); push(name); ;
}
#undef yythunkpos
Expand All @@ -482,6 +507,7 @@ YY_ACTION(void) yy_1_primary(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_primary\n"));
{
#line 104
push(makeVariable(yytext)); ;
}
#undef yythunkpos
Expand All @@ -495,6 +521,7 @@ YY_ACTION(void) yy_3_suffix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_3_suffix\n"));
{
#line 101
push(makePlus (pop())); ;
}
#undef yythunkpos
Expand All @@ -508,6 +535,7 @@ YY_ACTION(void) yy_2_suffix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_suffix\n"));
{
#line 100
push(makeStar (pop())); ;
}
#undef yythunkpos
Expand All @@ -521,6 +549,7 @@ YY_ACTION(void) yy_1_suffix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_suffix\n"));
{
#line 99
push(makeQuery(pop())); ;
}
#undef yythunkpos
Expand All @@ -534,6 +563,7 @@ YY_ACTION(void) yy_4_prefix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_4_prefix\n"));
{
#line 96
push(makePeekNot(pop())); ;
}
#undef yythunkpos
Expand All @@ -547,6 +577,7 @@ YY_ACTION(void) yy_3_prefix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_3_prefix\n"));
{
#line 95
push(makePeekFor(pop())); ;
}
#undef yythunkpos
Expand All @@ -560,6 +591,7 @@ YY_ACTION(void) yy_2_prefix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_prefix\n"));
{
#line 94
push(makePredicate(yytext)); ;
}
#undef yythunkpos
Expand All @@ -573,6 +605,7 @@ YY_ACTION(void) yy_1_prefix(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_prefix\n"));
{
#line 93
push(makeInline(yytext)); ;
}
#undef yythunkpos
Expand All @@ -586,6 +619,7 @@ YY_ACTION(void) yy_1_error(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_error\n"));
{
#line 90
push(makeError(pop(), yytext)); ;
}
#undef yythunkpos
Expand All @@ -599,6 +633,7 @@ YY_ACTION(void) yy_1_sequence(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_sequence\n"));
{
#line 87
Node *f= pop(); push(Sequence_append(pop(), f)); ;
}
#undef yythunkpos
Expand All @@ -612,6 +647,7 @@ YY_ACTION(void) yy_1_expression(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_expression\n"));
{
#line 84
Node *f= pop(); push(Alternate_append(pop(), f)); ;
}
#undef yythunkpos
Expand All @@ -625,6 +661,7 @@ YY_ACTION(void) yy_2_definition(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_definition\n"));
{
#line 81
Node *e= pop(); Rule_setExpression(pop(), e); ;
}
#undef yythunkpos
Expand All @@ -638,6 +675,7 @@ YY_ACTION(void) yy_1_definition(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_definition\n"));
{
#line 79
if (push(beginRule(findRule(yytext)))->rule.expression)
fprintf(stderr, "rule '%s' redefined\n", yytext); ;
}
Expand All @@ -652,6 +690,7 @@ YY_ACTION(void) yy_2_trailer(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_trailer\n"));
{
#line 77
makeTrailer(headerLine, yytext); ;
}
#undef yythunkpos
Expand All @@ -665,6 +704,7 @@ YY_ACTION(void) yy_1_trailer(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_trailer\n"));
{
#line 76
headerLine= lineNumber ;
}
#undef yythunkpos
Expand All @@ -678,6 +718,7 @@ YY_ACTION(void) yy_2_declaration(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_2_declaration\n"));
{
#line 74
makeHeader(headerLine, yytext); ;
}
#undef yythunkpos
Expand All @@ -691,6 +732,7 @@ YY_ACTION(void) yy_1_declaration(yycontext *yy, char *yytext, int yyleng)
#define yythunkpos yy->__thunkpos
yyprintf((stderr, "do yy_1_declaration\n"));
{
#line 72
headerLine= lineNumber; ;
}
#undef yythunkpos
Expand Down Expand Up @@ -1022,7 +1064,7 @@ YY_RULE(int) yy_AT(yycontext *yy)
}
YY_RULE(int) yy_action(yycontext *yy)
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos;
yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(yy, '{')) goto l73; yyText(yy, yy->__begin, yy->__end); {
yyprintf((stderr, "%s\n", "action")); if (!yymatchChar(yy, '{')) goto l73; yyDo(yy, yy_1_action, yy->__begin, yy->__end); yyText(yy, yy->__begin, yy->__end); {
#define yytext yy->__text
#define yyleng yy->__textlen
if (!(YY_BEGIN)) goto l73;
Expand Down Expand Up @@ -1353,7 +1395,7 @@ YY_PARSE(yycontext *) YYRELEASE(yycontext *yyctx)
}

#endif
#line 160 "src/leg.leg"
#line 163 "src/leg.leg"


void yyerror(char *message)
Expand Down Expand Up @@ -1408,6 +1450,7 @@ static void usage(char *name)
fprintf(stderr, "where <option> can be\n");
fprintf(stderr, " -h print this help information\n");
fprintf(stderr, " -o <ofile> write output to <ofile>\n");
fprintf(stderr, " -P do not generate #line directives\n");
fprintf(stderr, " -v be verbose\n");
fprintf(stderr, " -V print version number and exit\n");
fprintf(stderr, "if no <file> is given, input is read from stdin\n");
Expand All @@ -1425,7 +1468,7 @@ int main(int argc, char **argv)
lineNumber= 1;
fileName= "<stdin>";

while (-1 != (c= getopt(argc, argv, "Vho:v")))
while (-1 != (c= getopt(argc, argv, "PVho:v")))
{
switch (c)
{
Expand All @@ -1445,6 +1488,10 @@ int main(int argc, char **argv)
}
break;

case 'P':
nolinesFlag= 1;
break;

case 'v':
verboseFlag= 1;
break;
Expand Down Expand Up @@ -1496,10 +1543,13 @@ int main(int argc, char **argv)
fprintf(output, "#line %i \"%s\"\n%s\n", headers->line, fileName, headers->text);

if (rules)
Rule_compile_c(rules);
Rule_compile_c(rules, nolinesFlag);

if (trailer)
fprintf(output, "#line %i \"%s\"\n%s\n", trailerLine, fileName, trailer);
if (trailer) {
if (!nolinesFlag)
fprintf(output, "#line %i \"%s\"\n", trailerLine, fileName, trailer);
fprintf(output, "%s\n", trailer);
}

return 0;
}
Expand Down
Loading

0 comments on commit c8ec83c

Please sign in to comment.