]> git.lizzy.rs Git - nothing.git/blob - src/script/parser.h
Merge pull request #300 from tsoding/299
[nothing.git] / src / script / parser.h
1 #ifndef PARSER_H_
2 #define PARSER_H_
3
4 #include <stdio.h>
5 #include <stdbool.h>
6 #include "script/expr.h"
7 #include "script/tokenizer.h"
8
9 struct ParseError
10 {
11
12     size_t error_cursor;
13 };
14
15 struct ParseResult
16 {
17     bool is_error;
18     const char *end;
19     union {
20         struct Expr expr;
21         const char *error_message;
22     };
23 };
24
25 struct ParseResult parse_success(struct Expr expr,
26                                  const char *end);
27 struct ParseResult parse_failure(const char *error,
28                                  const char *end);
29
30 struct ParseResult parse_expr(struct Token token);
31
32 void print_parse_error(FILE *stream,
33                        const char *str,
34                        struct ParseResult result);
35
36 #endif  // PARSER_H_