2 #include "emp_ematch.yacc.h"
5 extern int ematch_argc;
6 extern char **ematch_argv;
8 #define NEXT_EM_ARG() do { ematch_argc--; ematch_argv++; } while(0);
10 #define YY_INPUT(buf, result, max_size) \
13 if (ematch_argc <= 0) \
15 else if (**ematch_argv == '\0') { \
19 if (max_size <= strlen(*ematch_argv) + 1) { \
20 fprintf(stderr, "match argument too long.\n"); \
23 strcpy(buf, *ematch_argv); \
24 result = strlen(*ematch_argv) + 1; \
25 buf[result-1] = ' '; \
32 static void __attribute__ ((unused)) yyunput (int c,char *buf_ptr );
33 static void __attribute__ ((unused)) yy_push_state (int new_state );
34 static void __attribute__ ((unused)) yy_pop_state (void);
35 static int __attribute__ ((unused)) yy_top_state (void );
40 %option 8bit stack warn bison-bridge noyywrap prefix="ematch_"
43 static unsigned char *strbuf;
44 static unsigned int strbuf_size;
45 static unsigned int strbuf_index;
47 static inline void strbuf_enlarge(void)
50 strbuf = realloc(strbuf, strbuf_size);
53 static inline void strbuf_append_char(unsigned char c)
55 while (strbuf_index >= strbuf_size)
57 strbuf[strbuf_index++] = c;
60 static inline void strbuf_append_charp(unsigned char *s)
62 while (strbuf_index >= strbuf_size)
64 memcpy(strbuf + strbuf_index, s, strlen(s));
65 strbuf_index += strlen(s);
73 strbuf = calloc(1, strbuf_size);
84 yylval->b = bstr_new(strbuf, strbuf_index);
85 yylval->b->quoted = 1;
89 <str>\\[0-7]{1,3} { /* octal escape sequence */
92 sscanf(yytext + 1, "%o", &res);
94 fprintf(stderr, "error: octal escape sequence" \
98 strbuf_append_char((unsigned char) res);
101 <str>\\[0-9]+ { /* catch wrong octal escape seq. */
102 fprintf(stderr, "error: invalid octale escape sequence\n");
106 <str>\\x[0-9a-fA-F]{1,2} {
109 sscanf(yytext + 2, "%x", &res);
112 fprintf(stderr, "error: hexadecimal escape " \
113 "sequence out of range\n");
116 strbuf_append_char((unsigned char) res);
119 <str>\\n strbuf_append_char('\n');
120 <str>\\r strbuf_append_char('\r');
121 <str>\\t strbuf_append_char('\t');
122 <str>\\v strbuf_append_char('\v');
123 <str>\\b strbuf_append_char('\b');
124 <str>\\f strbuf_append_char('\f');
125 <str>\\a strbuf_append_char('\a');
127 <str>\\(.|\n) strbuf_append_char(yytext[1]);
128 <str>[^\\\n\"]+ strbuf_append_charp(yytext);
130 [aA][nN][dD] return AND;
132 [nN][oO][tT] return NOT;
135 return yylval->i = *yytext;
138 yylval->b = bstr_alloc(yytext);
139 if (yylval->b == NULL)