#ifndef AMALGAM_PARSER_H #define AMALGAM_PARSER_H #include "std/buffer_view.h" #include "std/arena_allocator.h" #include "std/thread.h" #include "tokenizer.h" #include "ast.h" #include "defs.h" #include #define PARSER_OK 0 /* General error */ #define PARSER_ERR -1 #define PARSER_UNEXPECTED_TOKEN -2 typedef enum { ERROR_CONTEXT_NONE, ERROR_CONTEXT_RHS_STANDALONE, ERROR_CONTEXT_NO_LHS } ErrorContext; struct Parser { Tokenizer tokenizer; StructDecl struct_decl; LhsExpr file_decl; Scope *current_scope; bool has_func_parent; ArenaAllocator *allocator; /* Owned */ amal_compiler *compiler; Ir *ir; bool started; TokenizerError error; ErrorContext error_context; jmp_buf parse_env; Bytecode *bytecode; Buffer/**/ imports; HashMapType(BufferView, usize) imports_by_name; /* The value is an index inside @imports */ /* Index in the compilers list of parsers. Used by bytecodes import header to point to the index that contains references to another files variables. */ u32 index; }; CHECK_RESULT int parser_init(Parser *self, amal_compiler *compiler, ArenaAllocator *allocator); /* @buffer_name will be the path to the file when using parser_parse_file and when parsing a buffer you can name the buffer anything you want to identify it. Should only be called once for a parser object. */ CHECK_RESULT int parser_parse_buffer(Parser *self, BufferView code_buffer, BufferView buffer_name); /* Parses a file and the dependencies that are included using @import. Should only be called once for a parser object. */ CHECK_RESULT int parser_parse_file(Parser *self, BufferView filepath); #endif