diff options
author | Bad Diode <bd@badd10de.dev> | 2022-04-03 18:54:51 -0300 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-04-03 18:54:51 -0300 |
commit | c8b53cb4590d8d6cbfc5cbf891809ddd99e33fe5 (patch) | |
tree | 716f3676abb4a777add1683390cfc37a605fe911 /src/nodes.h | |
parent | 496ec36c8002a85dc0c3bb62de6d176e369b40af (diff) | |
download | bdl-c8b53cb4590d8d6cbfc5cbf891809ddd99e33fe5.tar.gz bdl-c8b53cb4590d8d6cbfc5cbf891809ddd99e33fe5.zip |
Add parsing for function definitions
This commits also changes the structure of some existing functions.
Namely, parse_* functions other than parse_next check that the type of
the token to parse is correct. This allow us to use them directly in the
rest of the code to consume tokens and properly produce an error if the
token type is not the expected one.
In the same fashion, two new functions consume_lparen and consume_rparen
are implemented. They only report true/false and report errors if
something went wrong.
Diffstat (limited to 'src/nodes.h')
-rw-r--r-- | src/nodes.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/nodes.h b/src/nodes.h index 566d6d3..2e24ea5 100644 --- a/src/nodes.h +++ b/src/nodes.h | |||
@@ -7,8 +7,10 @@ typedef enum NodeType { | |||
7 | NODE_BOOL, | 7 | NODE_BOOL, |
8 | NODE_STRING, | 8 | NODE_STRING, |
9 | NODE_SYMBOL, | 9 | NODE_SYMBOL, |
10 | NODE_TYPE, | ||
10 | NODE_DEF, | 11 | NODE_DEF, |
11 | NODE_SET, | 12 | NODE_SET, |
13 | NODE_FUN, | ||
12 | } NodeType; | 14 | } NodeType; |
13 | 15 | ||
14 | typedef struct Node { | 16 | typedef struct Node { |
@@ -38,13 +40,23 @@ typedef struct Node { | |||
38 | struct { | 40 | struct { |
39 | struct Node *symbol; | 41 | struct Node *symbol; |
40 | struct Node *value; | 42 | struct Node *value; |
41 | StringView type; | 43 | struct Node *type; |
42 | } def; | 44 | } def; |
43 | 45 | ||
46 | // Variable assignment. | ||
44 | struct { | 47 | struct { |
45 | struct Node *symbol; | 48 | struct Node *symbol; |
46 | struct Node *value; | 49 | struct Node *value; |
47 | } set; | 50 | } set; |
51 | |||
52 | // Function definition. | ||
53 | struct { | ||
54 | struct Node *name; | ||
55 | struct Node **param_names; | ||
56 | struct Node **param_types; | ||
57 | struct Node *return_type; | ||
58 | struct Node **body; | ||
59 | } fun; | ||
48 | }; | 60 | }; |
49 | } Node; | 61 | } Node; |
50 | 62 | ||