blob: 5c055d9c58c080964fcd8c1b283acb5ace51a686 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#ifndef AMALGAM_PARSER_H
#define AMALGAM_PARSER_H
#include "std/buffer_view.h"
#include "std/scoped_allocator.h"
#include "std/thread.h"
#include "tokenizer.h"
#include "ast.h"
#include "defs.h"
#include <setjmp.h>
#define PARSER_OK 0
/* General error */
#define PARSER_ERR -1
#define PARSER_UNEXPECTED_TOKEN -2
typedef enum {
PARSER_THREAD_STATUS_NEW,
PARSER_THREAD_STATUS_IDLE,
PARSER_THREAD_STATUS_RUNNING
} ParserThreadStatus;
struct ParserThreadData {
amal_thread thread;
ParserThreadStatus status;
ScopedAllocator allocator;
};
typedef enum {
ERROR_CONTEXT_NONE,
ERROR_CONTEXT_RHS_START
} ErrorContext;
typedef struct {
Tokenizer tokenizer;
Scope scope;
ScopedAllocator *allocator; /* borrowed. Copied from @compiler for faster access to allocator */
amal_compiler *compiler;
bool started;
TokenizerError error;
ErrorContext error_context;
jmp_buf parse_env;
} Parser;
CHECK_RESULT int parser_thread_data_init(ParserThreadData *self);
CHECK_RESULT int parser_thread_data_deinit(ParserThreadData *self);
CHECK_RESULT int parser_thread_data_start(ParserThreadData *self, AmalThreadCallbackFunc callback_func, void *userdata);
CHECK_RESULT int parser_thread_data_join(ParserThreadData *self, void **result);
CHECK_RESULT int parser_init(Parser *self, amal_compiler *compiler, ScopedAllocator *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
|