Get rid of lexer_error()

This commit is contained in:
Přemysl Eric Janouch 2017-05-19 09:48:53 +02:00
parent e76b7139ff
commit 53810d61f2
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 15 additions and 21 deletions

36
ell.c
View File

@ -277,12 +277,6 @@ lexer_advance (struct lexer *self) {
return c; return c;
} }
static inline bool
lexer_error (const char **e, const char *message) {
*e = message;
return false;
}
static bool static bool
lexer_hexa_escape (struct lexer *self, struct buffer *output) { lexer_hexa_escape (struct lexer *self, struct buffer *output) {
int i; int i;
@ -307,11 +301,10 @@ lexer_hexa_escape (struct lexer *self, struct buffer *output) {
return true; return true;
} }
static bool static const char *
lexer_escape_sequence (struct lexer *self, struct buffer *output, lexer_escape_sequence (struct lexer *self, struct buffer *output) {
const char **e) {
if (!self->len) if (!self->len)
return lexer_error (e, "premature end of escape sequence"); return "premature end of escape sequence";
unsigned char c = *self->p; unsigned char c = *self->p;
switch (c) { switch (c) {
@ -329,30 +322,31 @@ lexer_escape_sequence (struct lexer *self, struct buffer *output,
case 'X': case 'X':
lexer_advance (self); lexer_advance (self);
if (lexer_hexa_escape (self, output)) if (lexer_hexa_escape (self, output))
return true; return NULL;
return lexer_error (e, "invalid hexadecimal escape"); return "invalid hexadecimal escape";
default: default:
return lexer_error (e, "unknown escape sequence"); return "unknown escape sequence";
} }
buffer_append_c (output, c); buffer_append_c (output, c);
lexer_advance (self); lexer_advance (self);
return true; return NULL;
} }
static bool static const char *
lexer_string (struct lexer *self, struct buffer *output, const char **e) { lexer_string (struct lexer *self, struct buffer *output) {
unsigned char c; unsigned char c;
const char *e = NULL;
while (self->len) { while (self->len) {
if ((c = lexer_advance (self)) == '\'') if ((c = lexer_advance (self)) == '\'')
return true; return NULL;
if (c != '\\') if (c != '\\')
buffer_append_c (output, c); buffer_append_c (output, c);
else if (!lexer_escape_sequence (self, output, e)) else if ((e = lexer_escape_sequence (self, output)))
return false; return e;
} }
return lexer_error (e, "premature end of string"); return "premature end of string";
} }
static enum token static enum token
@ -385,7 +379,7 @@ lexer_next (struct lexer *self, const char **e) {
case '\'': case '\'':
lexer_advance (self); lexer_advance (self);
if (!lexer_string (self, &self->string, e)) if ((*e = lexer_string (self, &self->string)))
return T_ABORT; return T_ABORT;
return T_STRING; return T_STRING;
} }