-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
60 lines (51 loc) · 1.27 KB
/
parser.h
File metadata and controls
60 lines (51 loc) · 1.27 KB
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
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#define get_token()\
char_index++; \
if (c == '\t') { \
col += 4; \
} else if (c == '\n') { \
line += 1; col = 0; \
} else { \
col += 1; \
}
#define RED_FG "\x1b[31m"
#define COLOR_RESET "\x1b[0m"
#define abort_parsing(err_type, err_format, ...) \
char err_buffer[200]; \
sprintf(err_buffer, err_format, ##__VA_ARGS__); \
fprintf(stderr, "%s[X] %s:%s %s (line %d, col %d)\n", RED_FG, err_type, COLOR_RESET, err_buffer, line, col); \
exit(1)
#define PARSE_BUFFER_LENGTH 4096
#define EXP_LIST_LENGTH 128
//#define DEBUG
#ifdef DEBUG
#define debug(message, ...) printf(message, ##__VA_ARGS__)
#else
#define debug(message, ...)
#endif
enum parser_state {
START,
CAR,
ID,
WHITESPACE,
CDR,
FINISH,
};
struct sexp {
char *car;
char *id;
char *cdr_atom;
unsigned int cdr_atom_length;
/* Nested structures, not always used */
unsigned char cdr_subnodes;
struct sexp *cdr_list;
/* Error handling */
unsigned int opening_line, opening_col;
unsigned int closing_line, closing_col;
};
char *filter(char *content);
struct sexp parse_document(char *content);
struct sexp parse_expression(char *content);