libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1
8// TODO: this whole file
9
10#pragma once
11
12#include "def.h"
13#include "frontend/lexer/token.h" // ps_token
14#include "frontend/lexer/operator.h" // ps_operator_precedence_t
15#include "frontend/parser/tstream.h" // ps_tstream
16#include "frontend/parser/ast.h" // ps_node
17#include "util/io.h" // ps_file_ctx
18
19#ifndef PS_PARSER_MAX_ERRORS
21 #define PS_PARSER_MAX_ERRORS 5
22#endif
23
29struct ps_type_tuple* ps_parse_type_tuple(struct ps_tstream* ts);
30
34struct ps_type* ps_parse_type_primary(struct ps_tstream* ts);
35
39struct ps_type* ps_parse_type(struct ps_tstream* ts);
40
47struct ps_name* ps_parse_name(struct ps_tstream* ts, struct ps_token* first);
48
59struct ps_node_block* ps_parse_block(struct ps_tstream* ts);
60
64struct ps_node* ps_parse_let(struct ps_tstream* ts);
65
72struct ps_node* ps_parse_fn(struct ps_tstream* ts);
73
79struct ps_node* ps_parse_import(struct ps_tstream* ts);
80
86struct ps_node* ps_parse_extern(struct ps_tstream* ts);
87
89struct ps_node* ps_parse_expr_stm(struct ps_tstream* ts);
90
96struct ps_node* ps_parse_struct(struct ps_tstream* ts);
97
103struct ps_node* ps_parse_enum(struct ps_tstream* ts);
104
110struct ps_node* ps_parse_for(struct ps_tstream* ts);
111
113struct ps_node* ps_parse_while(struct ps_tstream* ts);
114
122struct ps_node* ps_parse_if(struct ps_tstream* ts);
123
129struct ps_node* ps_parse_return(struct ps_tstream* ts);
130
134struct ps_expr* ps_parse_interp_str(struct ps_tstream* ts);
135
137struct ps_expr* ps_parse_expr_lit(struct ps_tstream* ts);
138
144struct ps_expr* ps_parse_expr_call(struct ps_tstream* ts,
145 struct ps_token* callee);
146
152struct ps_expr* ps_parse_expr_primary(struct ps_tstream* ts);
153
162struct ps_expr* ps_parse_expr_helper(struct ps_tstream* ts, struct ps_expr* lhs,
163 ps_operator_precedence_t min_prec);
164
168struct ps_expr* ps_parse_expr(struct ps_tstream* ts);
169
175struct ps_node* ps_parse_node(struct ps_tstream* ts);
176
188struct ps_node_arr* ps_parse(struct ps_token_arr* tokens,
189 const struct ps_file_ctx* file_ctx);
Abstract syntax tree.
Base definitions.
Defines safe file I/O functions.
Operator precedence and associativity info.
i32 ps_operator_precedence_t
Definition operator.h:13
struct ps_expr * ps_parse_expr_lit(struct ps_tstream *ts)
Parses an expression literal.
Definition parser.c:519
struct ps_node * ps_parse_extern(struct ps_tstream *ts)
Parses an eexternal declaration.
Definition parser.c:362
struct ps_node * ps_parse_if(struct ps_tstream *ts)
Parses an if-else statement.
Definition parser.c:427
struct ps_type_tuple * ps_parse_type_tuple(struct ps_tstream *ts)
Parses a tuple type.
Definition parser.c:65
struct ps_node * ps_parse_enum(struct ps_tstream *ts)
Parses an enumeration declaration.
Definition parser.c:391
struct ps_node * ps_parse_for(struct ps_tstream *ts)
Parses a for loop.
Definition parser.c:399
struct ps_expr * ps_parse_expr_call(struct ps_tstream *ts, struct ps_token *callee)
Parses a call expression, which involves a token (TODO: an expression) followed by a set of parenthes...
Definition parser.c:578
struct ps_expr * ps_parse_expr_primary(struct ps_tstream *ts)
A primary expression is a literal or call expression.
Definition parser.c:609
struct ps_expr * ps_parse_expr(struct ps_tstream *ts)
Parses a general expression.
Definition parser.c:717
struct ps_type * ps_parse_type(struct ps_tstream *ts)
Parses a type such as Rectangle or (Point, Point) from the token stream.
Definition parser.c:122
struct ps_expr * ps_parse_interp_str(struct ps_tstream *ts)
Definition parser.c:486
struct ps_node * ps_parse_while(struct ps_tstream *ts)
Parses a while loop.
Definition parser.c:407
struct ps_node * ps_parse_return(struct ps_tstream *ts)
Parses a return statement.
Definition parser.c:457
struct ps_node_block * ps_parse_block(struct ps_tstream *ts)
Parses a block like:
Definition parser.c:149
struct ps_node * ps_parse_let(struct ps_tstream *ts)
Definition parser.c:179
struct ps_node * ps_parse_import(struct ps_tstream *ts)
Parses an import statement.
Definition parser.c:344
struct ps_type * ps_parse_type_primary(struct ps_tstream *ts)
Parses a primary type such as a tuple or unresolved (struct, enum).
Definition parser.c:98
struct ps_node * ps_parse_fn(struct ps_tstream *ts)
Parses a function definition.
Definition parser.c:229
struct ps_node * ps_parse_node(struct ps_tstream *ts)
Parses and returns the next node in ts.
Definition parser.c:721
struct ps_node * ps_parse_struct(struct ps_tstream *ts)
Parses a structure declaration.
Definition parser.c:383
struct ps_name * ps_parse_name(struct ps_tstream *ts, struct ps_token *first)
Parses a name such as foo::bar::baz.
Definition parser.c:133
struct ps_node_arr * ps_parse(struct ps_token_arr *tokens, const struct ps_file_ctx *file_ctx)
Constructs a series of nodes from the given tokens.
Definition parser.c:761
struct ps_expr * ps_parse_expr_helper(struct ps_tstream *ts, struct ps_expr *lhs, ps_operator_precedence_t min_prec)
Handles predence and associativity in parsing expressions.
Definition parser.c:674
struct ps_node * ps_parse_expr_stm(struct ps_tstream *ts)
An expression statement consists of an expression followed by a newline.
Definition parser.c:480
Expression nodes are represented with tagged unions.
Definition ast.h:187
Information captured in a file necessary for effective info/error reporting.
Definition io.h:15
AST nodes are represented with tagged unions.
Definition ast.h:206
Represents a token.
Definition token.h:34
Processes tokens in a stream.
Definition tstream.h:16
Definition type.h:66
Defines a token.
Token stream processing.