unput() have to hanppen in actions for flex 2.5.31, can do them in
user code sesction, so move up handle_comment and handle_string into action, not much sharing was done anyway. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16054 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
228
lib/asn1/lex.l
228
lib/asn1/lex.l
@@ -54,8 +54,8 @@ static unsigned lineno = 1;
|
|||||||
|
|
||||||
#undef ECHO
|
#undef ECHO
|
||||||
|
|
||||||
static void handle_comment(int type);
|
static void unterminated(const char *, unsigned);
|
||||||
static char *handle_string(void);
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
@@ -144,9 +144,109 @@ WITH { return kw_WITH; }
|
|||||||
"[" { return *yytext; }
|
"[" { return *yytext; }
|
||||||
"]" { return *yytext; }
|
"]" { return *yytext; }
|
||||||
::= { return EEQUAL; }
|
::= { return EEQUAL; }
|
||||||
-- { handle_comment(0); }
|
-- {
|
||||||
\/\* { handle_comment(1); }
|
int c, start_lineno = lineno;
|
||||||
"\"" { yylval.name = handle_string(); return STRING; }
|
int f = 0;
|
||||||
|
while((c = input()) != EOF) {
|
||||||
|
if(f && c == '-')
|
||||||
|
break;
|
||||||
|
if(c == '-') {
|
||||||
|
f = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(c == '\n') {
|
||||||
|
lineno++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
f = 0;
|
||||||
|
}
|
||||||
|
if(c == EOF)
|
||||||
|
unterminated("comment", start_lineno);
|
||||||
|
}
|
||||||
|
\/\* {
|
||||||
|
int c, start_lineno = lineno;
|
||||||
|
int level = 1;
|
||||||
|
int seen_star = 0;
|
||||||
|
int seen_slash = 0;
|
||||||
|
while((c = input()) != EOF) {
|
||||||
|
if(c == '/') {
|
||||||
|
if(seen_star) {
|
||||||
|
if(--level == 0)
|
||||||
|
break;
|
||||||
|
seen_star = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_slash = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(seen_star && c == '/') {
|
||||||
|
if(--level == 0)
|
||||||
|
break;
|
||||||
|
seen_star = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(c == '*') {
|
||||||
|
if(seen_slash) {
|
||||||
|
level++;
|
||||||
|
seen_star = seen_slash = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_star = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_star = seen_slash = 0;
|
||||||
|
if(c == '\n') {
|
||||||
|
lineno++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(c == EOF)
|
||||||
|
unterminated("comment", start_lineno);
|
||||||
|
}
|
||||||
|
"\"" {
|
||||||
|
int start_lineno = lineno;
|
||||||
|
int c;
|
||||||
|
char buf[1024];
|
||||||
|
char *p = buf;
|
||||||
|
int f = 0;
|
||||||
|
int skip_ws = 0;
|
||||||
|
|
||||||
|
while((c = input()) != EOF) {
|
||||||
|
if(isspace(c) && skip_ws) {
|
||||||
|
if(c == '\n')
|
||||||
|
lineno++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
skip_ws = 0;
|
||||||
|
|
||||||
|
if(c == '"') {
|
||||||
|
if(f) {
|
||||||
|
*p++ = '"';
|
||||||
|
f = 0;
|
||||||
|
} else
|
||||||
|
f = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(f == 1) {
|
||||||
|
unput(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(c == '\n') {
|
||||||
|
lineno++;
|
||||||
|
while(p > buf && isspace((unsigned char)p[-1]))
|
||||||
|
p--;
|
||||||
|
skip_ws = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*p++ = c;
|
||||||
|
}
|
||||||
|
if(c == EOF)
|
||||||
|
unterminated("string", start_lineno);
|
||||||
|
*p++ = '\0';
|
||||||
|
fprintf(stderr, "string -- %s\n", buf);
|
||||||
|
yylval.name = estrdup(buf);
|
||||||
|
return STRING;
|
||||||
|
}
|
||||||
|
|
||||||
-?0x[0-9A-Fa-f]+|-?[0-9]+ { char *e, *y = yytext;
|
-?0x[0-9A-Fa-f]+|-?[0-9]+ { char *e, *y = yytext;
|
||||||
yylval.constant = strtol((const char *)yytext,
|
yylval.constant = strtol((const char *)yytext,
|
||||||
@@ -178,119 +278,17 @@ yywrap ()
|
|||||||
void
|
void
|
||||||
error_message (const char *format, ...)
|
error_message (const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start (args, format);
|
va_start (args, format);
|
||||||
fprintf (stderr, "%s:%d: ", get_filename(), lineno);
|
fprintf (stderr, "%s:%d: ", get_filename(), lineno);
|
||||||
vfprintf (stderr, format, args);
|
vfprintf (stderr, format, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
error_flag++;
|
error_flag++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_comment(int type)
|
unterminated(const char *type, unsigned start_lineno)
|
||||||
{
|
{
|
||||||
int c;
|
error_message("unterminated %s, possibly started on line %d\n", type, start_lineno);
|
||||||
int start_lineno = lineno;
|
|
||||||
if(type == 0) {
|
|
||||||
int f = 0;
|
|
||||||
while((c = input()) != EOF) {
|
|
||||||
if(f && c == '-')
|
|
||||||
return;
|
|
||||||
if(c == '-') {
|
|
||||||
f = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(c == '\n') {
|
|
||||||
lineno++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
f = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int level = 1;
|
|
||||||
int seen_star = 0;
|
|
||||||
int seen_slash = 0;
|
|
||||||
while((c = input()) != EOF) {
|
|
||||||
if(c == '/') {
|
|
||||||
if(seen_star) {
|
|
||||||
if(--level == 0)
|
|
||||||
return;
|
|
||||||
seen_star = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
seen_slash = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(seen_star && c == '/') {
|
|
||||||
if(--level == 0)
|
|
||||||
return;
|
|
||||||
seen_star = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(c == '*') {
|
|
||||||
if(seen_slash) {
|
|
||||||
level++;
|
|
||||||
seen_star = seen_slash = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
seen_star = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
seen_star = seen_slash = 0;
|
|
||||||
if(c == '\n') {
|
|
||||||
lineno++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(c == EOF)
|
|
||||||
error_message("unterminated comment, possibly started on line %d\n", start_lineno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
handle_string(void)
|
|
||||||
{
|
|
||||||
int start_lineno = lineno;
|
|
||||||
int c;
|
|
||||||
char buf[1024];
|
|
||||||
char *p = buf;
|
|
||||||
int f = 0;
|
|
||||||
int skip_ws = 0;
|
|
||||||
|
|
||||||
while((c = input()) != EOF) {
|
|
||||||
if(isspace(c) && skip_ws) {
|
|
||||||
if(c == '\n')
|
|
||||||
lineno++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
skip_ws = 0;
|
|
||||||
|
|
||||||
if(c == '"') {
|
|
||||||
if(f) {
|
|
||||||
*p++ = '"';
|
|
||||||
f = 0;
|
|
||||||
} else
|
|
||||||
f = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(f == 1) {
|
|
||||||
unput(c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(c == '\n') {
|
|
||||||
lineno++;
|
|
||||||
while(p > buf && isspace((unsigned char)p[-1]))
|
|
||||||
p--;
|
|
||||||
skip_ws = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*p++ = c;
|
|
||||||
}
|
|
||||||
if(c == EOF)
|
|
||||||
error_message("unterminated string, possibly started on line %d\n", start_lineno);
|
|
||||||
*p++ = '\0';
|
|
||||||
fprintf(stderr, "string -- %s\n", buf);
|
|
||||||
return estrdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user