-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.h
More file actions
56 lines (49 loc) · 1.25 KB
/
Copy pathparse.h
File metadata and controls
56 lines (49 loc) · 1.25 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
#ifndef LEX_PARSE
#define LEX_PARSE
#include<stdbool.h>
/* selflex */
struct terminal;
struct pattern { char *name, *pattern; };
struct token { bool literal; char *name, *action; };
struct lexer {
char *pre, *post;
struct pattern *patterns;
size_t npat;
struct token *tokens;
size_t ntok;
};
/* lexer_create: returns a lexer. takes ownership of pre, post and l. */
struct lexer *
lexer_create(char *, char *, struct pattern *, size_t, struct token *, size_t);
void
lexer_destroy(struct lexer *);
/* parse: builds a lexer from the given input, according to the following
* grammar:
*
* file → defs meta rules subs
* subs → meta raw
* | ε
*
* defs → defsraw options defsproper
* defsraw → leftmeta raw rightmeta
* | ε
* options → '%option' id '\n' options
* | ε
* defsproper → def '\n' defs
* | ε
* def → id regex ('regex' as defined in thompson.h)
*
* rules → pattern { raw } '\n' rules
* | ε
* pattern → id
* | {·id·}
* | "·string·" (string potentially containing symbols)
*
* raw → .* (until end of environment EOF, '}', '}%', etc.)
* id → letter (letter | digit)*
* meta → '\n%%\n'
* leftmeta → '\n%{\n'
* rightmeta → '\n}%\n' */
struct lexer *
parse(char *input);
#endif