-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse_helpers.h
121 lines (101 loc) · 3.18 KB
/
parse_helpers.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef PARSE_HELPERS
#define PARSE_HELPERS
#include <stddef.h>
#include "ast.h"
#include "token.h"
#include "runtime/symboltable.h"
/* Methods that have special significance. */
#define SEG_METHOD_STRINGAPPEND "<<"
#define SEG_METHOD_STRINGCONV "as_string"
#define SEG_METHOD_STRINGINTERN "as_symbol"
struct seg_parser_context;
typedef struct seg_parser_context *seg_parser_contextp;
typedef struct {
seg_block_node *root;
seg_symboltable *symboltable;
seg_parser_contextp context;
} seg_parser_state;
/*
* Push a new `seg_parser_context` onto the stack each time a new block is opened. Notice that the
* parser context stack should initially be empty (that is, `NULL`).
*/
void seg_parser_pushcontext(seg_parser_state *state, seg_block_node *block);
/*
* Pop the top `seg_parser_context` from the context stack.
*/
void seg_parser_popcontext(seg_parser_state *state);
/*
* Add a parameter to the current block.
*/
void seg_parser_addparam(seg_parser_state *state, seg_parameter_list *param);
/*
* Return true iff `identifier` is used as a block argument in the current or a parent block.
*/
int seg_parser_isarg(seg_parser_state *state, const char *identifier, size_t length);
/*
* Append a new statement to a statement list. If `maybe` is NULL, return the original list
* unmodified.
*/
seg_block_node *seg_append_expr(seg_block_node *list, seg_expr_node *maybe);
/*
* Allocate a new seg_expr_node to model a binary operator application. `op` token will be destroyed
* after use.
*/
seg_expr_node *seg_parse_binop(
seg_parser_state *state,
seg_expr_node *lhs,
seg_token *op,
seg_expr_node *rhs
);
/*
* Allocate a new seg_expr_node to model an arbitrary method invocation. `selector` token will be
* destroyed after use. If `trim` is specified, a trailing `(` will be removed from the selector
* before parsing.
*/
seg_expr_node *seg_parse_methodcall(
seg_parser_state *state,
seg_expr_node *receiver,
seg_token *selector,
int trim,
seg_arg_list *args
);
/*
* Allocate a new seg_expr_node to model an implicit method call. `selector` should be a literal
* string.
*/
seg_expr_node *seg_implicit_methodcall(
seg_parser_state *state,
seg_expr_node *receiver,
const char *selector
);
/*
* Finish an interpolation expression. `middle` is the actual SEG_METHOD_STRINGAPPEND invocation,
* so it will actually be returned, with `stem` as its receiver and `end_token` wrapped in a String
* expression as a final argument.
*
* `end_token` will be destroyed by this call.
*/
seg_expr_node *seg_parse_interpolation(
seg_parser_state *state,
seg_expr_node *stem,
seg_expr_node *middle,
seg_token *end_token
);
/*
* Initialize a new seg_arg_list entry. `keyword` may be left NULL. If provided, `keyword` token
* will be destroyed after use.
*/
seg_arg_list *seg_parse_arg(seg_parser_state *state, seg_expr_node *value, seg_token *keyword);
/*
* Return a seg_expr_node that represents an implicit `self` reference.
*/
seg_expr_node *seg_implicit_self(seg_parser_state *state);
/*
* Reverse an argument list.
*/
seg_arg_list *seg_reverse_args(seg_arg_list *original);
/*
* Reverse a parameter list.
*/
seg_parameter_list *seg_reverse_params(seg_parameter_list *original);
#endif