libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
parse_statement.c File Reference
#include <string.h>
#include "module.h"
#include "parser.h"
#include "types/keywords.h"
Include dependency graph for parse_statement.c:

Go to the source code of this file.

Functions

unsigned int parse_statement (module_t *module, ast_node_t *parent, token_t *token)
 Parse a statement adding it as a children on parent AST node.
 

Function Documentation

◆ parse_statement()

unsigned int parse_statement ( module_t * module,
ast_node_t * parent,
token_t * token )

Parse a statement adding it as a children on parent AST node.

Parameters
moduleThe module where the AST is.
parentThe AST node parent for the statement.
tokenThe token where to start parsing the statement.
Returns
The number of tokens used on the statement.

Definition at line 8 of file parse_statement.c.

9{
10 if (token->type != TK_KEYWORD) {
12 module,
13 token->line,
16 "This token is unexpected here. It's expected to be a valid statement keyword.\n"
17 );
18
19 return 1;
20 }
21
22 switch (token->value) {
23 case KEY_INCLUDE:
24 return parse_statement_include(module, parent, token);
25 case KEY_SET:
26 return parse_statement_set(module, parent, token);
27 default:
28 return 1;
29 }
30}
@ KEY_SET
Definition keywords.h:10
@ KEY_INCLUDE
Definition keywords.h:7
void module_add_error(module_t *module, unsigned int line, unsigned int column, unsigned int length, const char *message)
Add error for the given module.
Definition module.c:92
unsigned int parse_statement_include(module_t *module, ast_node_t *parent, token_t *token)
Parse a include statement adding it as a children on parent AST node.
unsigned int parse_statement_set(module_t *module, ast_node_t *parent, token_t *token)
Parse a set statement adding it as a children on parent AST node.
unsigned int length
The length of the string.
Definition dstring.h:13
Struct that represents a Mya module.
Definition module.h:34
Struct for a Mya token.
Definition token.h:32
long long int value
Integer value of the token on TK_NUMBER tokens.
Definition token.h:36
token_type_t type
Token type.
Definition token.h:33
dstring_t lexeme
Lexeme of the token.
Definition token.h:37
unsigned int line
Token line inside the module.
Definition token.h:34
unsigned int column
Column of the token position on the line.
Definition token.h:35
@ TK_KEYWORD
Definition token.h:18