]> git.lizzy.rs Git - nothing.git/blob - src/script/parser.h
(#288) Introduce ParseError
[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
8 struct ParseError
9 {
10     const char *error_message;
11     size_t error_cursor;
12 };
13
14 struct ParseResult
15 {
16     bool is_error;
17     union {
18         struct Expr expr;
19         struct ParseError error;
20     };
21 };
22
23 struct ParseResult parse_success(struct Expr expr);
24 struct ParseResult parse_failure(const char *error,
25                                  size_t error_cursor);
26
27 struct ParseResult create_expr_from_str(const char *str,
28                                         size_t *cursor,
29                                         size_t n);
30
31 void print_parse_error(FILE *stream,
32                        const char *str,
33                        struct ParseError result);
34
35 #endif  // PARSER_H_