conquered parser_tests

This commit is contained in:
Tobias Lutke
2012-10-30 21:12:01 -04:00
parent cf765ebed3
commit a96cfd1297
2 changed files with 387 additions and 99 deletions

View File

@@ -3,18 +3,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define YYRULECOUNT 6
#define YYRULECOUNT 14
//uncomment to get more debug instrumentation
//
//#define YY_DEBUG
#include <ruby.h>
#define EMIT(sym, data) rb_ary_push(ctx->rb_tokens, rb_ary_new3(2, ID2SYM(rb_intern(sym)), data))
#define yy_rb_str rb_str_new(yytext, yyleng)
#define EMIT(sym, data) \
rb_ary_push(ctx->rb_tokens, rb_ary_new3(2, ID2SYM(rb_intern(sym)), data));
#define yy_rb_str rb_str_new(yytext, yyleng)
#define YYSTYPE VALUE
#define YY_CTX_LOCAL
#define YY_CTX_MEMBERS VALUE rb_tokens; char *p; int p_len;
#define YY_DEBUG
#define YY_INPUT(buf, result, max_size) { \
result = ctx->p_len; \
@@ -255,10 +259,18 @@ YY_LOCAL(void) yySet(yycontext *ctx, char *text, int count) { ctx->val[count]=
#define YYACCEPT yyAccept(ctx, yythunkpos0)
YY_RULE(int) yy_DIGIT(yycontext *ctx); /* 6 */
YY_RULE(int) yy_numeric(yycontext *ctx); /* 5 */
YY_RULE(int) yy_string(yycontext *ctx); /* 4 */
YY_RULE(int) yy_const(yycontext *ctx); /* 3 */
YY_RULE(int) yy_digit(yycontext *ctx); /* 14 */
YY_RULE(int) yy_float(yycontext *ctx); /* 13 */
YY_RULE(int) yy_integer(yycontext *ctx); /* 12 */
YY_RULE(int) yy_rangelet(yycontext *ctx); /* 11 */
YY_RULE(int) yy_identifier(yycontext *ctx); /* 10 */
YY_RULE(int) yy_accessors(yycontext *ctx); /* 9 */
YY_RULE(int) yy_numeric(yycontext *ctx); /* 8 */
YY_RULE(int) yy_string(yycontext *ctx); /* 7 */
YY_RULE(int) yy_const(yycontext *ctx); /* 6 */
YY_RULE(int) yy_hash(yycontext *ctx); /* 5 */
YY_RULE(int) yy_range(yycontext *ctx); /* 4 */
YY_RULE(int) yy_entity(yycontext *ctx); /* 3 */
YY_RULE(int) yy_primary(yycontext *ctx); /* 2 */
YY_RULE(int) yy_grammar(yycontext *ctx); /* 1 */
@@ -301,147 +313,397 @@ YY_ACTION(void) yy_1_const(yycontext *ctx, char *yytext, int yyleng)
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_const\n"));
yy = Qnil; ;
yy = Qtrue; ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_2_numeric(yycontext *ctx, char *yytext, int yyleng)
YY_ACTION(void) yy_1_integer(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_2_numeric\n"));
yy = rb_funcall(rb_cObject, rb_intern("Float"), 1, yy_rb_str); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_numeric(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_numeric\n"));
yyprintf((stderr, "do yy_1_integer\n"));
yy = rb_funcall(rb_cObject, rb_intern("Integer"), 1, yy_rb_str); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_float(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_float\n"));
yy = rb_funcall(rb_cObject, rb_intern("Float"), 1, yy_rb_str); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_2_string(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_2_string\n"));
yy = yy_rb_str; ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_string(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_string\n"));
yy = yy_rb_str; ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_range(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_range\n"));
EMIT("range", Qnil); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_rangelet(yycontext *ctx, char *yytext, int yyleng)
{
#define var ctx->val[-1]
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_rangelet\n"));
EMIT("id", var); ;
#undef yythunkpos
#undef yypos
#undef yy
#undef var
}
YY_ACTION(void) yy_1_entity(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_entity\n"));
EMIT("id", yy_rb_str); EMIT("lookup", Qnil); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_5_accessors(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_5_accessors\n"));
EMIT("id", yy_rb_str); EMIT("call", Qnil); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_4_accessors(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_4_accessors\n"));
EMIT("buildin", rb_str_new2("size")); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_3_accessors(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_3_accessors\n"));
EMIT("buildin", rb_str_new2("last")); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_2_accessors(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_2_accessors\n"));
EMIT("buildin", rb_str_new2("first")); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_1_accessors(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_accessors\n"));
EMIT("call", Qnil); ;
#undef yythunkpos
#undef yypos
#undef yy
}
YY_ACTION(void) yy_3_primary(yycontext *ctx, char *yytext, int yyleng)
{
#define var ctx->val[-1]
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_3_primary\n"));
EMIT("id", var); ;
#undef yythunkpos
#undef yypos
#undef yy
#undef var
}
YY_ACTION(void) yy_2_primary(yycontext *ctx, char *yytext, int yyleng)
{
#define var ctx->val[-1]
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_2_primary\n"));
EMIT("id", var); ;
#undef yythunkpos
#undef yypos
#undef yy
#undef var
}
YY_ACTION(void) yy_1_primary(yycontext *ctx, char *yytext, int yyleng)
{
#define v ctx->val[-1]
#define var ctx->val[-1]
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_primary\n"));
EMIT(:id, v); ;
EMIT("id", var); ;
#undef yythunkpos
#undef yypos
#undef yy
#undef var
}
YY_ACTION(void) yy_1_grammar(yycontext *ctx, char *yytext, int yyleng)
{
#define yy ctx->yy
#define yypos ctx->pos
#define yythunkpos ctx->thunkpos
yyprintf((stderr, "do yy_1_grammar\n"));
EMIT("lookup", Qnil); ;
#undef yythunkpos
#undef yypos
#undef yy
#undef v
}
YY_RULE(int) yy_DIGIT(yycontext *ctx)
YY_RULE(int) yy_digit(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "DIGIT")); if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\003\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 l1;
yyprintf((stderr, " ok %s @ %s\n", "DIGIT", ctx->buf+ctx->pos));
yyprintf((stderr, "%s\n", "digit")); if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\377\003\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 l1;
yyprintf((stderr, " ok %s @ %s\n", "digit", ctx->buf+ctx->pos));
return 1;
l1:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "DIGIT", ctx->buf+ctx->pos));
yyprintf((stderr, " fail %s @ %s\n", "digit", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_float(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "float")); yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l2;
{ int yypos3= ctx->pos, yythunkpos3= ctx->thunkpos; if (!yymatchChar(ctx, '-')) goto l3; goto l4;
l3:; ctx->pos= yypos3; ctx->thunkpos= yythunkpos3;
}
l4:; if (!yy_digit(ctx)) goto l2; if (!yymatchChar(ctx, '.')) goto l2; if (!yy_digit(ctx)) goto l2;
l5:;
{ int yypos6= ctx->pos, yythunkpos6= ctx->thunkpos; if (!yy_digit(ctx)) goto l6; goto l5;
l6:; ctx->pos= yypos6; ctx->thunkpos= yythunkpos6;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l2; yyDo(ctx, yy_1_float, ctx->begin, ctx->end);
yyprintf((stderr, " ok %s @ %s\n", "float", ctx->buf+ctx->pos));
return 1;
l2:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "float", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_integer(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "integer")); yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l7;
{ int yypos8= ctx->pos, yythunkpos8= ctx->thunkpos; if (!yymatchChar(ctx, '-')) goto l8; goto l9;
l8:; ctx->pos= yypos8; ctx->thunkpos= yythunkpos8;
}
l9:; if (!yy_digit(ctx)) goto l7;
l10:;
{ int yypos11= ctx->pos, yythunkpos11= ctx->thunkpos; if (!yy_digit(ctx)) goto l11; goto l10;
l11:; ctx->pos= yypos11; ctx->thunkpos= yythunkpos11;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l7; yyDo(ctx, yy_1_integer, ctx->begin, ctx->end);
yyprintf((stderr, " ok %s @ %s\n", "integer", ctx->buf+ctx->pos));
return 1;
l7:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "integer", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_rangelet(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyDo(ctx, yyPush, 1, 0);
yyprintf((stderr, "%s\n", "rangelet"));
{ int yypos13= ctx->pos, yythunkpos13= ctx->thunkpos; if (!yy_integer(ctx)) goto l14; yyDo(ctx, yySet, -1, 0); yyDo(ctx, yy_1_rangelet, ctx->begin, ctx->end); goto l13;
l14:; ctx->pos= yypos13; ctx->thunkpos= yythunkpos13; if (!yy_entity(ctx)) goto l12;
}
l13:;
yyprintf((stderr, " ok %s @ %s\n", "rangelet", ctx->buf+ctx->pos)); yyDo(ctx, yyPop, 1, 0);
return 1;
l12:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "rangelet", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_identifier(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "identifier")); if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\000\000\000\000\376\377\377\007\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l15; if (!yymatchClass(ctx, (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 l15;
l16:;
{ int yypos17= ctx->pos, yythunkpos17= ctx->thunkpos; if (!yymatchClass(ctx, (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 l17; goto l16;
l17:; ctx->pos= yypos17; ctx->thunkpos= yythunkpos17;
}
yyprintf((stderr, " ok %s @ %s\n", "identifier", ctx->buf+ctx->pos));
return 1;
l15:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "identifier", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_accessors(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "accessors"));
{ int yypos19= ctx->pos, yythunkpos19= ctx->thunkpos; if (!yy_hash(ctx)) goto l20; yyDo(ctx, yy_1_accessors, ctx->begin, ctx->end); goto l19;
l20:; ctx->pos= yypos19; ctx->thunkpos= yythunkpos19; if (!yymatchString(ctx, ".first")) goto l21; yyDo(ctx, yy_2_accessors, ctx->begin, ctx->end); goto l19;
l21:; ctx->pos= yypos19; ctx->thunkpos= yythunkpos19; if (!yymatchString(ctx, ".last")) goto l22; yyDo(ctx, yy_3_accessors, ctx->begin, ctx->end); goto l19;
l22:; ctx->pos= yypos19; ctx->thunkpos= yythunkpos19; if (!yymatchString(ctx, ".size")) goto l23; yyDo(ctx, yy_4_accessors, ctx->begin, ctx->end); goto l19;
l23:; ctx->pos= yypos19; ctx->thunkpos= yythunkpos19; if (!yymatchChar(ctx, '.')) goto l18; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l18; if (!yy_identifier(ctx)) goto l18; yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l18; yyDo(ctx, yy_5_accessors, ctx->begin, ctx->end);
}
l19:;
yyprintf((stderr, " ok %s @ %s\n", "accessors", ctx->buf+ctx->pos));
return 1;
l18:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "accessors", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_numeric(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "numeric"));
{ int yypos3= ctx->pos, yythunkpos3= ctx->thunkpos; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l4;
{ int yypos5= ctx->pos, yythunkpos5= ctx->thunkpos; if (!yymatchChar(ctx, '-')) goto l5; goto l6;
l5:; ctx->pos= yypos5; ctx->thunkpos= yythunkpos5;
{ int yypos25= ctx->pos, yythunkpos25= ctx->thunkpos; if (!yy_float(ctx)) goto l26; goto l25;
l26:; ctx->pos= yypos25; ctx->thunkpos= yythunkpos25; if (!yy_integer(ctx)) goto l24;
}
l6:; if (!yy_DIGIT(ctx)) goto l4;
l7:;
{ int yypos8= ctx->pos, yythunkpos8= ctx->thunkpos; if (!yy_DIGIT(ctx)) goto l8; goto l7;
l8:; ctx->pos= yypos8; ctx->thunkpos= yythunkpos8;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l4; yyDo(ctx, yy_1_numeric, ctx->begin, ctx->end); goto l3;
l4:; ctx->pos= yypos3; ctx->thunkpos= yythunkpos3; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l2;
{ int yypos9= ctx->pos, yythunkpos9= ctx->thunkpos; if (!yymatchChar(ctx, '-')) goto l9; goto l10;
l9:; ctx->pos= yypos9; ctx->thunkpos= yythunkpos9;
}
l10:; if (!yy_DIGIT(ctx)) goto l2; if (!yymatchChar(ctx, '.')) goto l2; if (!yy_DIGIT(ctx)) goto l2;
l11:;
{ int yypos12= ctx->pos, yythunkpos12= ctx->thunkpos; if (!yy_DIGIT(ctx)) goto l12; goto l11;
l12:; ctx->pos= yypos12; ctx->thunkpos= yythunkpos12;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l2; yyDo(ctx, yy_2_numeric, ctx->begin, ctx->end);
}
l3:;
l25:;
yyprintf((stderr, " ok %s @ %s\n", "numeric", ctx->buf+ctx->pos));
return 1;
l2:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
l24:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "numeric", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_string(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "string"));
{ int yypos14= ctx->pos, yythunkpos14= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l15; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l15;
l16:;
{ int yypos17= ctx->pos, yythunkpos17= ctx->thunkpos;
{ int yypos18= ctx->pos, yythunkpos18= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l18; goto l17;
l18:; ctx->pos= yypos18; ctx->thunkpos= yythunkpos18;
} if (!yymatchDot(ctx)) goto l17; goto l16;
l17:; ctx->pos= yypos17; ctx->thunkpos= yythunkpos17;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l15; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l15; goto l14;
l15:; ctx->pos= yypos14; ctx->thunkpos= yythunkpos14; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l13; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l13;
l19:;
{ int yypos20= ctx->pos, yythunkpos20= ctx->thunkpos;
{ int yypos21= ctx->pos, yythunkpos21= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l21; goto l20;
l21:; ctx->pos= yypos21; ctx->thunkpos= yythunkpos21;
} if (!yymatchDot(ctx)) goto l20; goto l19;
l20:; ctx->pos= yypos20; ctx->thunkpos= yythunkpos20;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l13; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l13;
{ int yypos28= ctx->pos, yythunkpos28= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l29; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l29;
l30:;
{ int yypos31= ctx->pos, yythunkpos31= ctx->thunkpos;
{ int yypos32= ctx->pos, yythunkpos32= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l32; goto l31;
l32:; ctx->pos= yypos32; ctx->thunkpos= yythunkpos32;
} if (!yymatchDot(ctx)) goto l31; goto l30;
l31:; ctx->pos= yypos31; ctx->thunkpos= yythunkpos31;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l29; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\200\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\000\000")) goto l29; yyDo(ctx, yy_1_string, ctx->begin, ctx->end); goto l28;
l29:; ctx->pos= yypos28; ctx->thunkpos= yythunkpos28; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l27; yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l27;
l33:;
{ int yypos34= ctx->pos, yythunkpos34= ctx->thunkpos;
{ int yypos35= ctx->pos, yythunkpos35= ctx->thunkpos; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l35; goto l34;
l35:; ctx->pos= yypos35; ctx->thunkpos= yythunkpos35;
} if (!yymatchDot(ctx)) goto l34; goto l33;
l34:; ctx->pos= yypos34; ctx->thunkpos= yythunkpos34;
} yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l27; if (!yymatchClass(ctx, (unsigned char *)"\000\000\000\000\004\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\000\000")) goto l27; yyDo(ctx, yy_2_string, ctx->begin, ctx->end);
}
l14:;
l28:;
yyprintf((stderr, " ok %s @ %s\n", "string", ctx->buf+ctx->pos));
return 1;
l13:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
l27:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "string", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_const(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "const"));
{ int yypos23= ctx->pos, yythunkpos23= ctx->thunkpos; if (!yymatchString(ctx, "true")) goto l24; yyDo(ctx, yy_1_const, ctx->begin, ctx->end); goto l23;
l24:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; if (!yymatchString(ctx, "false")) goto l25; yyDo(ctx, yy_2_const, ctx->begin, ctx->end); goto l23;
l25:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; if (!yymatchString(ctx, "nil")) goto l26; yyDo(ctx, yy_3_const, ctx->begin, ctx->end); goto l23;
l26:; ctx->pos= yypos23; ctx->thunkpos= yythunkpos23; if (!yymatchString(ctx, "null")) goto l22; yyDo(ctx, yy_4_const, ctx->begin, ctx->end);
{ int yypos37= ctx->pos, yythunkpos37= ctx->thunkpos; if (!yymatchString(ctx, "true")) goto l38; yyDo(ctx, yy_1_const, ctx->begin, ctx->end); goto l37;
l38:; ctx->pos= yypos37; ctx->thunkpos= yythunkpos37; if (!yymatchString(ctx, "false")) goto l39; yyDo(ctx, yy_2_const, ctx->begin, ctx->end); goto l37;
l39:; ctx->pos= yypos37; ctx->thunkpos= yythunkpos37; if (!yymatchString(ctx, "nil")) goto l40; yyDo(ctx, yy_3_const, ctx->begin, ctx->end); goto l37;
l40:; ctx->pos= yypos37; ctx->thunkpos= yythunkpos37; if (!yymatchString(ctx, "null")) goto l36; yyDo(ctx, yy_4_const, ctx->begin, ctx->end);
}
l23:;
l37:;
yyprintf((stderr, " ok %s @ %s\n", "const", ctx->buf+ctx->pos));
return 1;
l22:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
l36:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "const", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_hash(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "hash")); if (!yymatchChar(ctx, '[')) goto l41;
{ int yypos42= ctx->pos, yythunkpos42= ctx->thunkpos; if (!yy_primary(ctx)) goto l43; goto l42;
l43:; ctx->pos= yypos42; ctx->thunkpos= yythunkpos42; if (!yy_entity(ctx)) goto l41;
}
l42:; if (!yymatchChar(ctx, ']')) goto l41;
yyprintf((stderr, " ok %s @ %s\n", "hash", ctx->buf+ctx->pos));
return 1;
l41:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "hash", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_range(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "range")); if (!yymatchChar(ctx, '(')) goto l44; if (!yy_rangelet(ctx)) goto l44; if (!yymatchString(ctx, "..")) goto l44; if (!yy_rangelet(ctx)) goto l44; if (!yymatchChar(ctx, ')')) goto l44; yyDo(ctx, yy_1_range, ctx->begin, ctx->end);
yyprintf((stderr, " ok %s @ %s\n", "range", ctx->buf+ctx->pos));
return 1;
l44:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "range", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_entity(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "entity")); yyText(ctx, ctx->begin, ctx->end); if (!(YY_BEGIN)) goto l45; if (!yy_identifier(ctx)) goto l45; yyText(ctx, ctx->begin, ctx->end); if (!(YY_END)) goto l45; yyDo(ctx, yy_1_entity, ctx->begin, ctx->end);
l46:;
{ int yypos47= ctx->pos, yythunkpos47= ctx->thunkpos; if (!yy_accessors(ctx)) goto l47; goto l46;
l47:; ctx->pos= yypos47; ctx->thunkpos= yythunkpos47;
}
yyprintf((stderr, " ok %s @ %s\n", "entity", ctx->buf+ctx->pos));
return 1;
l45:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "entity", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_primary(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos; yyDo(ctx, yyPush, 1, 0);
yyprintf((stderr, "%s\n", "primary"));
{ int yypos28= ctx->pos, yythunkpos28= ctx->thunkpos; if (!yy_const(ctx)) goto l29; yyDo(ctx, yySet, -1, 0); goto l28;
l29:; ctx->pos= yypos28; ctx->thunkpos= yythunkpos28; if (!yy_string(ctx)) goto l30; yyDo(ctx, yySet, -1, 0); goto l28;
l30:; ctx->pos= yypos28; ctx->thunkpos= yythunkpos28; if (!yy_numeric(ctx)) goto l27; yyDo(ctx, yySet, -1, 0);
{ int yypos49= ctx->pos, yythunkpos49= ctx->thunkpos; if (!yy_const(ctx)) goto l50; yyDo(ctx, yySet, -1, 0); yyDo(ctx, yy_1_primary, ctx->begin, ctx->end); goto l49;
l50:; ctx->pos= yypos49; ctx->thunkpos= yythunkpos49; if (!yy_string(ctx)) goto l51; yyDo(ctx, yySet, -1, 0); yyDo(ctx, yy_2_primary, ctx->begin, ctx->end); goto l49;
l51:; ctx->pos= yypos49; ctx->thunkpos= yythunkpos49; if (!yy_numeric(ctx)) goto l48; yyDo(ctx, yySet, -1, 0); yyDo(ctx, yy_3_primary, ctx->begin, ctx->end);
}
l28:; yyDo(ctx, yy_1_primary, ctx->begin, ctx->end);
l49:;
yyprintf((stderr, " ok %s @ %s\n", "primary", ctx->buf+ctx->pos)); yyDo(ctx, yyPop, 1, 0);
return 1;
l27:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
l48:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "primary", ctx->buf+ctx->pos));
return 0;
}
YY_RULE(int) yy_grammar(yycontext *ctx)
{ int yypos0= ctx->pos, yythunkpos0= ctx->thunkpos;
yyprintf((stderr, "%s\n", "grammar")); if (!yy_primary(ctx)) goto l31;
yyprintf((stderr, "%s\n", "grammar"));
{ int yypos53= ctx->pos, yythunkpos53= ctx->thunkpos; if (!yy_primary(ctx)) goto l54; goto l53;
l54:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_entity(ctx)) goto l55; goto l53;
l55:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_range(ctx)) goto l56; goto l53;
l56:; ctx->pos= yypos53; ctx->thunkpos= yythunkpos53; if (!yy_hash(ctx)) goto l52; yyDo(ctx, yy_1_grammar, ctx->begin, ctx->end);
}
l53:;
yyprintf((stderr, " ok %s @ %s\n", "grammar", ctx->buf+ctx->pos));
return 1;
l31:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
l52:; ctx->pos= yypos0; ctx->thunkpos= yythunkpos0;
yyprintf((stderr, " fail %s @ %s\n", "grammar", ctx->buf+ctx->pos));
return 0;
}
@@ -495,10 +757,8 @@ VALUE liquid_context_parse_impl(VALUE self, VALUE text) {
yyprintf((stderr, "About to start: %s %d\n", ctx.p, ctx.p_len));
//while(yyparse(&ctx))
// ;
// ;
yyparse(&ctx);
yyparse(&ctx);
yyparse(&ctx);
return ctx.rb_tokens;

View File

@@ -1,15 +1,19 @@
%{
//uncomment to get more debug instrumentation
//
//#define YY_DEBUG
#include <ruby.h>
#define EMIT(sym, data) rb_ary_push(ctx->rb_tokens, rb_ary_new3(2, ID2SYM(rb_intern(sym)), data))
#define yy_rb_str rb_str_new(yytext, yyleng)
#define EMIT(sym, data) \
rb_ary_push(ctx->rb_tokens, rb_ary_new3(2, ID2SYM(rb_intern(sym)), data));
#define yy_rb_str rb_str_new(yytext, yyleng)
#define YYSTYPE VALUE
#define YY_CTX_LOCAL
#define YY_CTX_MEMBERS VALUE rb_tokens; char *p; int p_len;
#define YY_DEBUG
#define YY_INPUT(buf, result, max_size) { \
result = ctx->p_len; \
@@ -25,31 +29,57 @@
%}
grammar = primary
| entity
| range
| hash { EMIT("lookup", Qnil); }
;
hash = '[' (primary|entity) ']';
primary = ( v:const
| v:string
| v:numeric
) { EMIT(:id, v); }
primary = var:const { EMIT("id", var); }
| var:string { EMIT("id", var); }
| var:numeric { EMIT("id", var); }
;
accessors = hash { EMIT("call", Qnil); }
| '.first' { EMIT("buildin", rb_str_new2("first")); }
| '.last' { EMIT("buildin", rb_str_new2("last")); }
| '.size' { EMIT("buildin", rb_str_new2("size")); }
| '.' <identifier> { EMIT("id", yy_rb_str); EMIT("call", Qnil); }
;
string = ['] < ( !['] . )* > [']
| ["] < ( !["] . )* > ["]
entity = <identifier> { EMIT("id", yy_rb_str); EMIT("lookup", Qnil); }
accessors*
;
rangelet = var:integer { EMIT("id", var); }
| entity
;
range = '(' rangelet '..' rangelet ')' { EMIT("range", Qnil); }
string = ['] < ( !['] . )* > ['] { $$ = yy_rb_str; }
| ["] < ( !["] . )* > ["] { $$ = yy_rb_str; }
;
numeric = <'-'? DIGIT+> { $$ = rb_funcall(rb_cObject, rb_intern("Integer"), 1, yy_rb_str); }
| <'-'? DIGIT'.'DIGIT+> { $$ = rb_funcall(rb_cObject, rb_intern("Float"), 1, yy_rb_str); }
numeric = float
| integer
;
float = <'-'? digit'.'digit+> { $$ = rb_funcall(rb_cObject, rb_intern("Float"), 1, yy_rb_str); }
integer = <'-'? digit+> { $$ = rb_funcall(rb_cObject, rb_intern("Integer"), 1, yy_rb_str); }
const = 'true' { $$ = Qnil; }
const = "true" { $$ = Qtrue; }
| 'false' { $$ = Qfalse; }
| 'nil' { $$ = Qnil; }
| 'null' { $$ = Qnil; }
;
DIGIT = [0-9];
digit = [0-9];
identifier = [a-zA-Z][a-zA-Z0-9_\-]+;
%%
VALUE liquid_context_parse_impl(VALUE self, VALUE text) {
@@ -65,10 +95,8 @@ VALUE liquid_context_parse_impl(VALUE self, VALUE text) {
yyprintf((stderr, "About to start: %s %d\n", ctx.p, ctx.p_len));
//while(yyparse(&ctx))
// ;
// ;
yyparse(&ctx);
yyparse(&ctx);
yyparse(&ctx);
return ctx.rb_tokens;