blob: bdf052f865daf95ba4d8669c5d99d8b424f36cfd (
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
|
#ifndef ROSCHA_PARSER_H
#define ROSCHA_PARSER_H
#include "ast.h"
#include "hmap.h"
#include "lexer.h"
#include "token.h"
#include "vector.h"
#include "sds/sds.h"
struct parser {
/* The name of the template; transfered to resulting template AST */
char *name;
/* The lexer that is ought to tokenize our input */
struct lexer *lexer;
/* Current token */
struct token cur_token;
/* Next token */
struct token peek_token;
/*
* Temporary field that holds {% block ... %} tags, for easier/faster
* access to said blocks without having to traverse all the AST, in case the
* template is a child template. This hashmap will be transfered to the
* resulting AST upon finishing parsing.
*/
struct hmap *tblocks;
/* vector of sds */
struct vector *errors;
};
typedef struct expression *(*prefix_parse_f)(struct parser *);
typedef struct expression *(*infix_parse_f)(struct parser *, struct expression *);
/* Allocate a new parser */
struct parser *parser_new(char *name, char *input);
/* Parse template into an AST */
struct template *parser_parse_template(struct parser *);
/* Free all memory asociated with the parser */
void parser_destroy(struct parser *);
/*
* Initialize variables needed for parsing; may be used by several parsers.
*/
void parser_init(void);
/*
* Free all static memory related to parsing; called when parsing/evaluation is
* no longer needed
*/
void parser_deinit(void);
#endif
|