aboutsummaryrefslogtreecommitdiff
path: root/src/lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/lex.l')
-rw-r--r--src/lex.l41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/lex.l b/src/lex.l
index 7b043bf1..c33f2a62 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -1,6 +1,6 @@
%{
/* This file is part of mailfromd.
- Copyright (C) 2005, 2006, 2007 Sergey Poznyakoff
+ Copyright (C) 2005, 2006, 2007, 2008 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -85,10 +85,26 @@ keyword(int kw)
} while (0)
static int
-get_const(const char *name)
+variable_or_const()
{
- struct value *value_ptr;
- if (value_ptr = constant_lookup(name)) {
+ union {
+ struct variable *vptr;
+ struct constant *cptr;
+ } v;
+ const struct value *value_ptr;
+
+ switch (variable_or_constant_lookup(yylval.literal->text, &v)) {
+ case SYM_UNDEF:
+ parse_error(_("Variable %s is not defined"),
+ yylval.literal->text);
+ return BOGUS;
+
+ case SYM_VARIABLE:
+ yylval.var = v.vptr;
+ return VARIABLE;
+
+ case SYM_CONSTANT:
+ value_ptr = &v.cptr->value;
switch (value_ptr->type) {
case dtype_number:
yylval.number = value_ptr->v.number;
@@ -102,8 +118,8 @@ get_const(const char *name)
abort();
}
}
- return 0;
}
+
static size_t input_line;
@@ -259,19 +275,14 @@ end return keyword(KW_END);
/* Variables */
<INITIAL,ONBLOCK,ML,CML,STR>\%({ICONST}) { return builtin_const(yytext+1); }
<INITIAL,ONBLOCK,ML,CML,STR>\%{IDENT} {
- int rc;
string(yytext + 1, yyleng - 1);
- if ((rc = get_const(yylval.literal->text)) != 0)
- return rc;
- else
- return VARIABLE; }
+ return variable_or_const();
+}
<INITIAL,ONBLOCK,ML,CML,STR>\%\{{IDENT}\} {
- int rc;
string(yytext + 2, yyleng - 3);
- if ((rc = get_const(yylval.literal->text)) != 0)
- return rc;
- else
- return VARIABLE; }
+ return variable_or_const();
+}
+
/* Positional arguments */
<INITIAL,ONBLOCK,ML,CML,STR>\$# {
return ARGCOUNT;

Return to:

Send suggestions and report system problems to the System administrator.