From 104142d87e31a02ce014a4ad3fefcb2c1c21602b Mon Sep 17 00:00:00 2001 From: Vlad Vissoultchev Date: Sun, 5 Feb 2017 13:36:28 +0200 Subject: [PATCH 1/2] Allow skip capture text buffer population --- compile.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/compile.c b/compile.c index 4ee9251..e2a0b4b 100644 --- a/compile.c +++ b/compile.c @@ -506,6 +506,9 @@ static const char *preamble= "\ #ifndef YY_BUFFER_START_SIZE\n\ #define YY_BUFFER_START_SIZE 1024\n\ #endif\n\ +#ifndef YY_TEXT_START_SIZE\n\ +#define YY_TEXT_START_SIZE 1024\n\ +#endif\n\ \n\ #ifndef YY_PART\n\ #define yydata G->data\n\ @@ -648,7 +651,7 @@ YY_LOCAL(int) yyText(GREG *G, int begin, int end)\n\ int yyleng= end - begin;\n\ if (yyleng <= 0)\n\ yyleng= 0;\n\ - else\n\ + else if (G->text)\n\ {\n\ while (G->textlen < (yyleng + 1))\n\ {\n\ @@ -657,7 +660,7 @@ YY_LOCAL(int) yyText(GREG *G, int begin, int end)\n\ }\n\ memcpy(G->text, G->buf + begin, yyleng);\n\ }\n\ - G->text[yyleng]= '\\0';\n\ + if (G->text) G->text[yyleng]= '\\0';\n\ return yyleng;\n\ }\n\ \n\ @@ -736,8 +739,8 @@ YY_PARSE(int) YY_NAME(parse_from)(GREG *G, yyrule yystart)\n\ {\n\ G->buflen= YY_BUFFER_START_SIZE;\n\ G->buf= (char*)YY_ALLOC(G->buflen, G->data);\n\ - G->textlen= YY_BUFFER_START_SIZE;\n\ - G->text= (char*)YY_ALLOC(G->textlen, G->data);\n\ + G->textlen= YY_TEXT_START_SIZE;\n\ + G->text= (char*)(G->textlen ? YY_ALLOC(G->textlen, G->data) : 0);\n\ G->thunkslen= YY_STACK_SIZE;\n\ G->thunks= (yythunk*)YY_ALLOC(sizeof(yythunk) * G->thunkslen, G->data);\n\ G->valslen= YY_STACK_SIZE;\n\ From 833992e34fc8e26343ad3db50bb75cb21860e72f Mon Sep 17 00:00:00 2001 From: Vlad Vissoultchev Date: Sun, 5 Feb 2017 14:04:17 +0200 Subject: [PATCH 2/2] Define yybuf and yycapture in actions --- compile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index e2a0b4b..12ae8fa 100644 --- a/compile.c +++ b/compile.c @@ -512,11 +512,13 @@ static const char *preamble= "\ \n\ #ifndef YY_PART\n\ #define yydata G->data\n\ +#define yybuf G->buf\n\ +#define yycapture (*thunk)\n\ #define yy G->ss\n\ \n\ struct _yythunk; /* forward declaration */\n\ typedef void (*yyaction)(struct _GREG *G, char *yytext, int yyleng, struct _yythunk *thunkpos, YY_XTYPE YY_XVAR);\n\ -typedef struct _yythunk { int begin, end; yyaction action; const char *name; struct _yythunk *next; } yythunk;\n\ +typedef struct _yythunk { int begin, end; yyaction action; const char *name; } yythunk;\n\ \n\ typedef struct _GREG {\n\ char *buf;\n\