~lattis/muon

ref: f9a8cbad39b665a9496cd3adb4756e85ee5ec97c muon/include/lang/lexer.h -rw-r--r-- 1.1 KiB
f9a8cbadStone Tickle print stdout/stderr of failing test 8 months ago
                                                                                
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
#ifndef MUON_LANG_LEXER_H
#define MUON_LANG_LEXER_H

#include <stdbool.h>
#include <stdint.h>

#include "data/darr.h"
#include "lang/eval.h"

enum token_type {
	tok_eof,
	tok_eol,
	tok_lparen,
	tok_rparen,
	tok_lbrack,
	tok_rbrack,
	tok_lcurl,
	tok_rcurl,
	tok_dot,
	tok_comma,
	tok_colon,
	tok_question_mark,

	/* math */
	tok_plus,
	tok_minus,
	tok_star,
	tok_slash,
	tok_modulo,

	/* assign */
	tok_assign,
	tok_plus_assign,

	/* comparison */
	tok_eq,
	tok_neq,
	tok_gt,
	tok_geq,
	tok_lt,
	tok_leq,

	/* keywords */
	tok_if,
	tok_else,
	tok_elif,
	tok_endif,
	tok_and,
	tok_or,
	tok_not,
	tok_foreach,
	tok_endforeach,
	tok_in,
	tok_continue,
	tok_break,

	/* literals */
	tok_identifier,
	tok_string,
	tok_number,
	tok_true,
	tok_false,
};

struct token {
	union token_data dat;
	enum token_type type;
	uint32_t n, line, col;
};

struct tokens {
	struct darr tok;
};

bool lexer_lex(struct tokens *toks, struct source_data *sdata, struct source *src);
void tokens_destroy(struct tokens *toks);

const char *tok_type_to_s(enum token_type type);
const char *tok_to_s(struct token *token);
#endif