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 13f5d569e328ba379140c6f9d841e5d5fca4108d
Author: swagtoy <m...@ow.swag.toys>
AuthorDate: Tue Nov 19 13:18:20 2024 -0500

    lexer: Some identifier lexing (broken)
---
 escript/include/lexer.h |  1 +
 escript/src/lexer.c     | 37 ++++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/escript/include/lexer.h b/escript/include/lexer.h
index 6e118dd..14a7e26 100644
--- a/escript/include/lexer.h
+++ b/escript/include/lexer.h
@@ -6,6 +6,7 @@
 #define ESCRIPT_LEXER_H
 #include <stddef.h>
 #include "eina_inarray.h"
+#include "eina_strbuf.h"
 
 enum Escript_Lex_Keywords
 {
diff --git a/escript/src/lexer.c b/escript/src/lexer.c
index e0d971b..e6aff56 100644
--- a/escript/src/lexer.c
+++ b/escript/src/lexer.c
@@ -51,15 +51,29 @@ next_nb(struct Escript_Lexer* lex)
 }
 
 // locale agnostic?
-#define PRINTABLE_ASCII(x) (isupper(x) || islower(x))
-
-void
-lex_keyword(struct Escript_Lexer* lex)
+// also genuinely do not know what to call it
+static inline int
+identifier_like_char(char x, int i)
 {
-	while (PRINTABLE_ASCII(at(0)) && !eol(lex, 0))
+	// TODO if isnum(x) and i == 0 return 0
+	return (isupper(x) || islower(x) || x == '_') && x != ' ';
+}
+
+// Keywords are also identifiers, I think. Regardless, 
+static Eina_Strbuf* const
+lex_identifier(struct Escript_Lexer* lex)
+{
+	// TODO maybe less allocations? unless strbuf is optimized for no insertions now
+	Eina_Strbuf* const res = eina_strbuf_new();
+	
+	while (identifier_like_char(at(0), 0/*TODO*/) && !eol(lex, 0))
 	{
+		eina_strbuf_append_char(res, at(0));
 		next_char(lex, 0);
 	}
+	if (eina_strbuf_length_get(res))
+		return NULL;
+	return res;
 }
 
 int
@@ -70,6 +84,8 @@ escript_lexer_step(struct Escript_Lexer* lex)
 	};
 	
 	next_nb(lex);
+	if (eol(lex, 1))
+		return 0;
 	switch (at(0))
 	{
 	case '$': // variable sigil
@@ -78,11 +94,18 @@ escript_lexer_step(struct Escript_Lexer* lex)
 		eina_inarray_push(lex->lex, &token);
 		break;
 	default: // Raw keyword or something
-		//lex_keyword(lex);
-		putchar(lex->current[0]);
+	{
+		Eina_Strbuf* ident = lex_identifier(lex);
+		if (ident)
+		{
+			printf("[%s]", eina_strbuf_string_get(ident));
+			eina_strbuf_free(ident);
+		}
 		break;
 	}
+	}
 	next_char(lex, 0);
+
 }
 
 int

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to