summaryrefslogtreecommitdiff
path: root/42sh/src/parser/parser.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /42sh/src/parser/parser.c
add: added projectsHEADmain
Diffstat (limited to '42sh/src/parser/parser.c')
-rw-r--r--42sh/src/parser/parser.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/42sh/src/parser/parser.c b/42sh/src/parser/parser.c
new file mode 100644
index 0000000..7c6a1b2
--- /dev/null
+++ b/42sh/src/parser/parser.c
@@ -0,0 +1,40 @@
+#include "parser/parser.h"
+
+#include <stdlib.h>
+
+#include "ast/ast_accessors.h"
+#include "lexer/token.h"
+#include "parser/parser_functions.h"
+#include "parser/parser_utils.h"
+
+struct ast *parse(struct lexer *lexer, enum parser_state *state)
+{
+ struct token next = lexer_peek(lexer);
+
+ if (next.type == TOKEN_EOF || next.type == TOKEN_NEWLINE)
+ {
+ lexer_pop(lexer);
+ return NULL;
+ }
+
+ struct ast *res = parse_list(lexer, state);
+
+ next = lexer_peek(lexer);
+
+ if (error_check(res, state, next))
+ {
+ return NULL;
+ }
+
+ lexer_pop(lexer);
+
+ if (next.type == TOKEN_EOF || next.type == TOKEN_NEWLINE)
+ {
+ return res;
+ }
+ else
+ {
+ cleanup(res, state);
+ return NULL;
+ }
+}