-
Notifications
You must be signed in to change notification settings - Fork 1
/
syntax.h
42 lines (37 loc) · 979 Bytes
/
syntax.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
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <pcre2.h>
struct syntax_token {
enum syntax_token_kind {
SYNTAX_TOKEN_NONE,
SYNTAX_TOKEN_COMMENT,
SYNTAX_TOKEN_IDENTIFIER,
SYNTAX_TOKEN_LITERAL_CHAR,
SYNTAX_TOKEN_LITERAL_NUMBER,
SYNTAX_TOKEN_LITERAL_STRING,
SYNTAX_TOKEN_PREPROC,
SYNTAX_TOKEN_PUNCTUATION,
SYNTAX_TOKEN_STATEMENT,
SYNTAX_TOKEN_TYPE,
} kind;
size_t pos;
size_t len;
};
struct syntax;
typedef void (*tokenizer_func)(struct syntax*, struct syntax_token*, size_t);
struct syntax {
struct buffer *buffer;
tokenizer_func tokenizer;
size_t pos;
enum syntax_state {
STATE_INIT,
STATE_PREPROC
} state;
pcre2_code *regex;
pcre2_match_data *groups;
};
char *syntax_detect_filetype(char *path);
bool syntax_init(struct syntax *syntax, struct buffer *buffer);
void syntax_deinit(struct syntax *syntax);
void syntax_token_at(struct syntax *syntax, struct syntax_token *token, size_t pos);