summaryrefslogtreecommitdiff
path: root/src/compiler/parser.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-23 15:39:11 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-23 15:39:11 +0330
commitf91fc3bac670a8c775c7ea7b8ba8789dba9559ad (patch)
treee227022c0c2fa09fc52f47519f3c1815590651b8 /src/compiler/parser.c
parent157475f0bd929a9b42b6cd9a4ca7f4fc4e64bf71 (diff)
prepairing more for importing
Diffstat (limited to 'src/compiler/parser.c')
-rw-r--r--src/compiler/parser.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler/parser.c b/src/compiler/parser.c
index f5009e5..f0d3e9b 100644
--- a/src/compiler/parser.c
+++ b/src/compiler/parser.c
@@ -1,6 +1,7 @@
#include "parser.h"
#include "compiler/lexer.h"
+#include "utils/file.h"
#include "utils/log.h"
#include "utils/memory.h"
#include "utils/string.h"
@@ -667,6 +668,23 @@ ParserNode *newParserNode(ParserToken token, char *str_begin, char *str_end,
return parserNode;
}
+ParserNode *parserFromPath(const char *filePath) {
+ char *code = readWholeFile(filePath);
+ if (code == NULL) {
+ return NULL;
+ }
+
+ LexerNodeArray lexed = lexer(code);
+ if (lexerNodeArrayIsError(lexed)) {
+ return NULL;
+ }
+
+ ParserNode *root = parser(lexed);
+ lexerNodeArrayDestroy(lexed);
+
+ return root;
+}
+
ParserNode *parser(LexerNodeArray lexed) {
ParserNode *root = newParserNode(PARSER_TOKEN_ROOT, NULL, NULL, NULL, NULL);
if (parserNodeArray(lexed.data, lexed.data + lexed.size, root)) {