-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlexer.h
123 lines (95 loc) · 3.86 KB
/
lexer.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
122
123
#include <stddef.h> /* size_t */
#include "lexer-callbacks.h"
#define LEXER_EOF 0x7fffffff
struct lexer;
struct lexer_arg {
const char *path;
const struct buffer *bf;
struct diffchunk *diff;
const struct options *op;
/*
* Report errors immediately, removing the need to call
* lexer_error_flush() explicitly.
*/
int error_flush;
struct {
struct arena_scope *eternal_scope;
struct arena *scratch;
} arena;
struct lexer_callbacks callbacks;
};
struct lexer_state {
struct token *st_tk;
size_t st_off;
unsigned int st_lno;
struct {
unsigned int error:1,
eof:1;
} st_flags;
};
struct lexer *lexer_tokenize(const struct lexer_arg *);
struct lexer_state lexer_get_state(const struct lexer *);
void lexer_set_state(struct lexer *,
const struct lexer_state *);
const char *lexer_get_path(const struct lexer *);
int lexer_get_peek(const struct lexer *);
int lexer_getc(struct lexer *, unsigned char *);
void lexer_ungetc(struct lexer *);
size_t lexer_match(struct lexer *, const char *);
void lexer_eat_lines_and_spaces(struct lexer *,
struct lexer_state *);
struct token *lexer_emit(struct lexer *, const struct lexer_state *, int);
struct token *lexer_emit_template(struct lexer *, const struct lexer_state *,
const struct token *);
struct token *lexer_emit_synthetic(struct lexer *, const struct token *);
const char *lexer_serialize(struct lexer *, const struct token *);
int lexer_eat_lines(struct lexer *, int, struct token **);
int lexer_eat_spaces(struct lexer *, struct token **);
void lexer_error(struct lexer *, const struct token *, const char *, int,
const char *, ...) __attribute__((__format__(printf, 5, 6)));
void lexer_error_flush(struct lexer *);
void lexer_error_reset(struct lexer *);
const char *lexer_buffer_slice(const struct lexer *,
const struct lexer_state *, size_t *);
int lexer_eof(const struct lexer *);
unsigned int lexer_get_error(const struct lexer *);
int lexer_get_lines(const struct lexer *, unsigned int,
unsigned int, const char **, size_t *);
void lexer_seek(struct lexer *, struct token *);
int lexer_seek_after(struct lexer *, struct token *);
int lexer_pop(struct lexer *, struct token **);
int lexer_back(const struct lexer *, struct token **);
int lexer_back_if(const struct lexer *, int, struct token **);
struct token *lexer_copy_after(struct lexer *, struct token *,
const struct token *);
struct token *lexer_insert_after(struct lexer *, struct token *,
const struct token *);
struct token *lexer_move_after(struct lexer *, struct token *,
struct token *);
struct token *lexer_move_before(struct lexer *, struct token *,
struct token *);
void lexer_remove(struct lexer *, struct token *);
#define lexer_expect(a, b, c) \
lexer_expect_impl((a), (b), (c), __func__, __LINE__)
int lexer_expect_impl(struct lexer *, int, struct token **,
const char *, int);
void lexer_peek_enter(struct lexer *, struct lexer_state *);
void lexer_peek_leave(struct lexer *, const struct lexer_state *);
int lexer_peek(struct lexer *, struct token **);
int lexer_peek_if(struct lexer *, int, struct token **);
int lexer_if(struct lexer *, int, struct token **);
int lexer_peek_if_flags(struct lexer *, unsigned int, struct token **);
int lexer_if_flags(struct lexer *, unsigned int, struct token **);
int lexer_peek_if_pair(struct lexer *, int, int, struct token **,
struct token **);
int lexer_if_pair(struct lexer *, int, int, struct token **,
struct token **);
int lexer_peek_if_prefix_flags(struct lexer *, unsigned int,
struct token **);
int lexer_peek_until(struct lexer *, int, struct token **);
int lexer_peek_until_comma(struct lexer *, const struct token *,
struct token **);
int lexer_until(struct lexer *, int, struct token **);
int lexer_peek_first(struct lexer *, struct token **);
int lexer_peek_last(struct lexer *, struct token **);
void lexer_dump(struct lexer *);