aboutsummaryrefslogtreecommitdiff
path: root/src/grecs-lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/grecs-lex.l')
-rw-r--r--src/grecs-lex.l133
1 files changed, 9 insertions, 124 deletions
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index 4d491fe..84ee858 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -3,7 +3,6 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-#include "yygrecs.h"
}
%{
/* grecs - Gray's Extensible Configuration System
@@ -48,12 +47,9 @@ grecs_locus_t grecs_current_locus; /* Input file location */
*/
static size_t xlines;
-static struct grecs_list *line_acc;
-
static void multiline_begin(char *);
static void multiline_add(char *);
static char *multiline_strip_tabs(char *text);
-static void line_add_unescape_last(char *text, size_t len);
static int ident(void);
static int isemptystr(int off);
@@ -113,9 +109,10 @@ P [1-9][0-9]*
\"[^\\"\n]*\\. |
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
- line_add_unescape_last(yytext + 1, yyleng - 1); }
+ grecs_line_acc_grow_unescape_last(yytext + 1,
+ yyleng - 1); }
<STR>[^\\"\n]*\\. |
-<STR>\"[^\\"\n]*\\\n { line_add_unescape_last(yytext, yyleng); }
+<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
grecs_line_add(yytext, yyleng - 1);
@@ -170,20 +167,12 @@ yywrap()
return 1;
}
-static void
-line_acc_free_entry(void *ptr)
-{
- grecs_free(ptr);
-}
-
int
-grecs_lex_begin(const char *name)
+grecs_lex_begin(const char *name, int trace)
{
- if (yy_flex_debug > 0)
- yy_flex_debug = 0;
+ yy_flex_debug = trace;
- line_acc = grecs_list_create();
- line_acc->free_entry = line_acc_free_entry;
+ grecs_line_acc_create();
if (grecs_preprocessor) {
int fd;
@@ -211,7 +200,7 @@ grecs_lex_begin(const char *name)
void
grecs_lex_end(int err)
{
- grecs_list_clear(line_acc);
+ grecs_line_acc_free();
}
static int
@@ -239,95 +228,21 @@ multiline_strip_tabs(char *text)
return text;
}
-static int
-unquote_char(int c)
-{
- static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
-
- char *p;
-
- for (p = quote_transtab; *p; p += 2) {
- if (*p == c)
- return p[1];
- }
- return -1;
-}
-
-struct line_acc_entry
-{
- size_t size;
-};
-#define line_acc_ptr(entry) (char*)(entry + 1)
-
-static void
-line_acc_add_string(const char *str, size_t len)
-{
- struct line_acc_entry *ent = grecs_malloc(sizeof(*ent) + len + 1);
- char *p = line_acc_ptr(ent);
- memcpy(p, str, len);
- p[len] = 0;
- ent->size = len;
- grecs_list_append(line_acc, ent);
-}
-
-static void
-line_acc_add_char(int c)
-{
- char t = c;
- line_acc_add_string(&t, 1);
-}
-
-static void
-list_acc_unescape_char(int c)
-{
- if (c != '\n') {
- int t = unquote_char(c);
- if (t != -1)
- line_acc_add_char(t);
- else {
- grecs_warning(&grecs_current_locus, 0,
- _("unknown escape sequence '\\%c'"),
- c);
- line_acc_add_char(c);
- }
- }
-}
-
-void
-grecs_line_add(const char *text, size_t len)
-{
- line_acc_add_string(text, len);
-}
-
-/* Same, but unescapes the last character from yytext */
-static void
-line_add_unescape_last(char *text, size_t len)
-{
- line_acc_add_string(text, len - 2);
- list_acc_unescape_char(text[len - 1]);
-}
-
static void
multiline_add(char *s)
{
if (multiline_unescape) {
for (; *s; s++) {
if (*s == '\\') {
- list_acc_unescape_char(s[1]);
+ grecs_line_acc_grow_char_unescape(s[1]);
++s;
} else
- line_acc_add_char(*s);
+ grecs_line_acc_grow_char(*s);
}
} else
grecs_line_add(s, strlen(s));
}
-void
-grecs_line_begin()
-{
- /* FIXME: nothing so far. Maybe prepare stk by calling obstack_finish? */
-}
-
static int
is_tab(char c)
{
@@ -374,30 +289,6 @@ multiline_begin(char *p)
grecs_line_begin();
}
-char *
-grecs_line_finish()
-{
- struct grecs_list_entry *ep;
- size_t size = 0;
- char *str, *p;
-
- for (ep = line_acc->head; ep; ep = ep->next) {
- struct line_acc_entry *ent = ep->data;
- size += ent->size;
- }
-
- str = grecs_malloc(size + 1);
- for (ep = line_acc->head, p = str; ep; ep = ep->next) {
- struct line_acc_entry *ent = ep->data;
- char *str = line_acc_ptr(ent);
- memcpy(p, str, ent->size);
- p += ent->size;
- }
- *p = 0;
- grecs_list_clear(line_acc);
- return str;
-}
-
static int
ident()
{
@@ -416,12 +307,6 @@ ident()
return IDENT;
}
-void
-grecs_lex_trace(int n)
-{
- yy_flex_debug = -n;
-}
-
grecs_value_t *
grecs_value_ptr_from_static(grecs_value_t *input)
{

Return to:

Send suggestions and report system problems to the System administrator.