From 53810d61f20296ce9ef207811e1180b6d10d7a24 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Fri, 19 May 2017 09:48:53 +0200
Subject: Get rid of lexer_error()
---
ell.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/ell.c b/ell.c
index f34acdd..c1f784f 100755
--- a/ell.c
+++ b/ell.c
@@ -277,12 +277,6 @@ lexer_advance (struct lexer *self) {
return c;
}
-static inline bool
-lexer_error (const char **e, const char *message) {
- *e = message;
- return false;
-}
-
static bool
lexer_hexa_escape (struct lexer *self, struct buffer *output) {
int i;
@@ -307,11 +301,10 @@ lexer_hexa_escape (struct lexer *self, struct buffer *output) {
return true;
}
-static bool
-lexer_escape_sequence (struct lexer *self, struct buffer *output,
- const char **e) {
+static const char *
+lexer_escape_sequence (struct lexer *self, struct buffer *output) {
if (!self->len)
- return lexer_error (e, "premature end of escape sequence");
+ return "premature end of escape sequence";
unsigned char c = *self->p;
switch (c) {
@@ -329,30 +322,31 @@ lexer_escape_sequence (struct lexer *self, struct buffer *output,
case 'X':
lexer_advance (self);
if (lexer_hexa_escape (self, output))
- return true;
- return lexer_error (e, "invalid hexadecimal escape");
+ return NULL;
+ return "invalid hexadecimal escape";
default:
- return lexer_error (e, "unknown escape sequence");
+ return "unknown escape sequence";
}
buffer_append_c (output, c);
lexer_advance (self);
- return true;
+ return NULL;
}
-static bool
-lexer_string (struct lexer *self, struct buffer *output, const char **e) {
+static const char *
+lexer_string (struct lexer *self, struct buffer *output) {
unsigned char c;
+ const char *e = NULL;
while (self->len) {
if ((c = lexer_advance (self)) == '\'')
- return true;
+ return NULL;
if (c != '\\')
buffer_append_c (output, c);
- else if (!lexer_escape_sequence (self, output, e))
- return false;
+ else if ((e = lexer_escape_sequence (self, output)))
+ return e;
}
- return lexer_error (e, "premature end of string");
+ return "premature end of string";
}
static enum token
@@ -385,7 +379,7 @@ lexer_next (struct lexer *self, const char **e) {
case '\'':
lexer_advance (self);
- if (!lexer_string (self, &self->string, e))
+ if ((*e = lexer_string (self, &self->string)))
return T_ABORT;
return T_STRING;
}
--
cgit v1.2.3-70-g09d2