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 c146fef6ffcab50efeb4377a42218adfc72cf6ac
Author: swagtoy <m...@ow.swag.toys>
AuthorDate: Thu Nov 21 18:42:58 2024 -0500
lexer: Better stringification
Doesn't compile right now, I will fix later at home
---
escript/include/lexer.h | 29 +++++++++++------------
escript/include/stringify.h | 14 +++++++++++
escript/src/lexer.c | 12 ++++++----
escript/src/meson.build | 3 ++-
escript/src/stringify.c | 57 ++++++++++++++++++++++++++++++++++++++-------
escript/src/stringify.h | 1 +
6 files changed, 88 insertions(+), 28 deletions(-)
diff --git a/escript/include/lexer.h b/escript/include/lexer.h
index b54b6c2..ebc5cd1 100644
--- a/escript/include/lexer.h
+++ b/escript/include/lexer.h
@@ -9,7 +9,6 @@
#include <stddef.h>
#include "eina_inarray.h"
#include "eina_strbuf.h"
-
enum Escript_Lex_Keywords
{
ELEX_WHILE,
@@ -46,13 +45,13 @@ enum Escript_Lex_Keywords
ELEX_CONDITIONAL, // ? :
// comparison
- ELEX_COMP_EQ, // ==
- ELEX_COMP_NEQ, // !=
- ELEX_COMP_LT, // <
- ELEX_COMP_GT, // >
- ELEX_COMP_LTEQ, // <=
- ELEX_COMP_GTEQ, // >=
- ELEX_COMP_SPACESHIP, // <=>
+ ELEX_CMP_EQ, // ==
+ ELEX_CMP_NEQ, // !=
+ ELEX_CMP_LT, // <
+ ELEX_CMP_GT, // >
+ ELEX_CMP_LTEQ, // <=
+ ELEX_CMP_GTEQ, // >=
+ ELEX_CMP_SPACESHIP, // <=>
// numbery operators
ELEX_PLUS,
@@ -63,13 +62,13 @@ enum Escript_Lex_Keywords
ELEX_FLOORDIVIDE,
ELEX_POW,
- // bitshift (it's possible!)
- ELEX_BIT_AND, //&
- ELEX_BIT_OR, //|
- ELEX_BIT_XOR, //^
- ELEX_BIT_NOT, //~
- ELEX_LSHIFT, //<<
- ELEX_RSHIFT, //>>
+ // bitshift (not final)
+ /* ELEX_BIT_AND, //& */
+ /* ELEX_BIT_OR, //| */
+ /* ELEX_BIT_XOR, //^ */
+ /* ELEX_BIT_NOT, //~ */
+ /* ELEX_BIT_LSHIFT, //<< */
+ /* ELEX_BIT_RSHIFT, //>> */
};
struct Escript_Token_String
diff --git a/escript/include/stringify.h b/escript/include/stringify.h
new file mode 100644
index 0000000..2ffb684
--- /dev/null
+++ b/escript/include/stringify.h
@@ -0,0 +1,14 @@
+/* Escript - stringify.c
+ * ---
+ * Copyright (c) 2024 Hyland B. (swagtoy)
+ * Licensed under BSD 2-Clause
+ */
+
+// Bunch of stringification functions
+#ifndef ESCRIPT_STRINGIFY_H
+#define ESCRIPT_STRINGIFY_H
+
+char const* const
+escript_lexer_token_to_string(struct Escript_Token* token);
+
+#endif // ESCRIPT_STRINGIFY_H
diff --git a/escript/src/lexer.c b/escript/src/lexer.c
index 079ab9f..944cf89 100644
--- a/escript/src/lexer.c
+++ b/escript/src/lexer.c
@@ -6,8 +6,9 @@
#include <stdio.h>
#include <string.h>
-#include "lexer.h"
#include <ctype.h>
+#include "lexer.h"
+#include "stringify.h"
#define at(i) lex->current[i]
@@ -83,15 +84,15 @@ lex_identifier(struct Escript_Lexer* lex)
}
-
+// TODO: Move to stringify
char const* const
escript_token_info_str(struct Escript_Token* token)
{
Eina_Strbuf* const res = eina_strbuf_new();
eina_strbuf_append_printf(res,
- "Token: %d\n"
+ "Token: %s\n"
"Data: yes"
- ,token->token);
+ ,escript_lexer_token_to_string(token->token));
return eina_strbuf_string_steal(res);
}
@@ -125,9 +126,11 @@ escript_lexer_step(struct Escript_Lexer* lex)
case ';':
PUSH_SIMPLE_TOKEN(ELEX_SEMICOLON);
break;
+
case '$': // variable sigil
PUSH_SIMPLE_TOKEN(ELEX_SIGIL);
break;
+
default: // Raw keyword or something
{
Eina_Strbuf* ident = lex_identifier(lex);
@@ -156,6 +159,7 @@ escript_lexer_step(struct Escript_Lexer* lex)
}
}
break;
+
}
dont_skip_step:
step_char(lex, 0);
diff --git a/escript/src/meson.build b/escript/src/meson.build
index d1728ef..3c7b6a0 100644
--- a/escript/src/meson.build
+++ b/escript/src/meson.build
@@ -1,4 +1,5 @@
libescript_files = files([
'escript.c',
- 'lexer.c'
+ 'lexer.c',
+ 'stringify.c',
])
diff --git a/escript/src/stringify.c b/escript/src/stringify.c
index c46e6ba..faf2d04 100644
--- a/escript/src/stringify.c
+++ b/escript/src/stringify.c
@@ -13,16 +13,57 @@
char const* const
escript_lexer_token_to_string(struct Escript_Token* token)
{
-#define STR_TOK(x, ret) case ELEX_ ## x: return ref;
+#define STR_TOK(x) case ELEX_ ## x: return #x;
switch (token->token)
{
- STR_TOK(WHILE, "while")
- STR_TOK(IF, "if")
- STR_TOK(UNLESS, "unless")
- STR_TOK(DO, "do")
- STR_TOK(FUN, "fun")
- STR_TOK(TYPE, "type")
+ STR_TOK(WHILE)
+ STR_TOK(IF)
+ STR_TOK(UNLESS)
+ STR_TOK(DO)
+ STR_TOK(FUN)
+ STR_TOK(TYPE)
+ STR_TOK(STRING)
+ STR_TOK(BOOL)
+ STR_TOK(TABLE)
+ STR_TOK(ARRAY)
+ STR_TOK(INT)
+ STR_TOK(DOUBLE)
+ STR_TOK(NULL)
+ STR_TOK(IDENTIFIER)
+ STR_TOK(FUNCTION_DECL)
+ STR_TOK(PAREN_BEGIN)
+ STR_TOK(PAREN_END)
+ STR_TOK(QUOTE)
+ STR_TOK(STR_QUOTE)
+ STR_TOK(STR_SINGLEQUOTE)
+ STR_TOK(BLOCK_BEGIN)
+ STR_TOK(BLOCK_END)
+ STR_TOK(SEMICOLON)
+ STR_TOK(COLON)
+ STR_TOK(ASSIGN)
+ STR_TOK(SIGIL)
+ STR_TOK(CONDITIONAL)
+ STR_TOK(CMP_EQ)
+ STR_TOK(CMP_NEQ)
+ STR_TOK(CMP_LT)
+ STR_TOK(CMP_GT)
+ STR_TOK(CMP_LTEQ)
+ STR_TOK(CMP_GTEQ)
+ STR_TOK(CMP_SPACESHIP)
+ STR_TOK(PLUS)
+ STR_TOK(MINUS)
+ STR_TOK(DIVIDE)
+ STR_TOK(MULTIPLY)
+ STR_TOK(FLOORDIVIDE)
+ STR_TOK(POW)
+ /* STR_TOK(BIT_AND) */
+ /* STR_TOK(BIT_OR) */
+ /* STR_TOK(BIT_XOR) */
+ /* STR_TOK(BIT_NOT) */
+ /* STR_TOK(BIT_LSHIFT) */
+ /* STR_TOK(BIT_RSHIFT) */
default: return "";
}
-#undef STRINGIFY
+ return NULL;
+#undef STR_TOK
}
diff --git a/escript/src/stringify.h b/escript/src/stringify.h
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/escript/src/stringify.h
@@ -0,0 +1 @@
+
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.