This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository eshell.
View the commit online.
commit 7e6c56b3cae0575870bfd8ffd2e19bc3a6caa7f2
Author: swagtoy <m...@ow.swag.toys>
AuthorDate: Thu Nov 14 13:09:36 2024 -0500
lexer: Lexer stepping
---
escript/include/lexer.h | 20 +++++++++-----------
escript/src/lexer.c | 49 ++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/escript/include/lexer.h b/escript/include/lexer.h
index 4afeed5..37ef413 100644
--- a/escript/include/lexer.h
+++ b/escript/include/lexer.h
@@ -7,17 +7,6 @@
#include <stddef.h>
#include "eina_array.h"
-enum Escript_Lex_Types
-{
- ELEXT_STRING,
- ELEXT_BOOL,
- ELEXT_TABLE,
- ELEXT_ARRAY,
- ELEXT_INT,
- ELEXT_DOUBLE,
- ELEXT_NULL,
-};
-
enum Escript_Lex_Keywords
{
ELEX_WHILE,
@@ -26,6 +15,15 @@ enum Escript_Lex_Keywords
ELEX_DO,
ELEX_FUN,
ELEX_TYPE,
+
+ // Types
+ ELEX_STRING,
+ ELEX_BOOL,
+ ELEX_TABLE,
+ ELEX_ARRAY,
+ ELEX_INT,
+ ELEX_DOUBLE,
+ ELEX_NULL,
ELEX_VAR,
ELEX_COMMAND,
diff --git a/escript/src/lexer.c b/escript/src/lexer.c
index 27d600b..93caffc 100644
--- a/escript/src/lexer.c
+++ b/escript/src/lexer.c
@@ -8,37 +8,64 @@
#include <string.h>
#include "lexer.h"
#include "eina_array.h"
+
+#define at(i) lex->current[i]
int
escript_lexer_init(struct Escript_Lexer* lex)
{
+ // Initialize array
}
static char const*
-next_char(struct Escript_Lexer* lex)
+next_char(struct Escript_Lexer* lex, int step)
{
- lex->current_len--;
- return lex->current++;
+ for (int i = 0; i < step + 1; ++i)
+ {
+ lex->current_len--;
+ lex->current++;
+ }
}
+static inline int eol(struct Escript_Lexer* lex, int step)
+{
+ return lex->current_len - step <= 0;
+}
-
-static char const*
+static int
next_nb(struct Escript_Lexer* lex)
{
- for (;;)
+ while (!eol(lex, 0))
{
- char const* x = next_char(lex);
- if (*x != ' ' || *x != '\t')
- break;
+ switch (at(0))
+ {
+ case ' ': case '\t':
+ next_char(lex, 0);
+ break;
+ default:
+ return 1;
+ }
}
- return lex->current;
+ return 0;
+}
+
+int
+escript_lexer_step(struct Escript_Lexer* lex)
+{
+ next_nb(lex);
+ putchar(lex->current[0]);
+ next_char(lex, 0);
}
int
escript_lexer_lex(struct Escript_Lexer* lex, char const* string, size_t string_len)
{
- lex->current = next_char(lex);
+ // State maintained by all functions
+ lex->current = string;
+ lex->current_len = string_len == -1 ? strlen(string) : string_len;
+
+ while (!eol(lex, 0))
+ escript_lexer_step(lex);
}
void
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.