-
Notifications
You must be signed in to change notification settings - Fork 0
/
mllexgen.h
83 lines (61 loc) · 2.53 KB
/
mllexgen.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
#ifndef YYML_Moonlime_HEADER
#define YYML_Moonlime_HEADER
/* The default lexical-scanner template for Moonlime. Terms under which the
* generated code may be distributed, modified, etc. are provided by the
* lexer-writer below. */
/* A lexer for Moonlime lexers.
* Copyright © 2012 Zachary Catlin. See LICENSE for terms. */
#define ML_ML_LEXER_H
#ifndef ML_UTILS_H
#include "utils.h"
#endif
#ifndef ML_REGEX_H
#include "regex.h"
#endif
typedef enum {
D_NONE,
D_TOP,
D_HEADER,
D_STATE,
D_INITSTATE,
D_PREFIX,
D_USTATE_TYPE
} directive_kind;
struct pattern_entry {
regex_t *rx;
len_string *code;
lstr_list_t *states;
struct pattern_entry *next;
};
typedef struct pattern_entry pat_entry_t;
typedef struct {
directive_kind dir; /* Current type of directive being parsed */
int c_nest_depth; /* Current brace-nesting depth in C code */
int regex_nest_depth; /* Current parenthesis-nesting depth in regex */
len_string *code; /* The current chunk of C code */
regex_t *curr_rx; /* Current regular-expression fragment being worked on */
regex_t *rx_stack; /* Stack of regular-expression fragments -- only
* types R_CONCAT, R_OPTION, and R_PAREN should be on
* the stack! */
lstr_list_t *curr_st; /* List of start states for current fragment */
pat_entry_t *phead; /* First element in the list of regular expression/
* code action pairs */
pat_entry_t *ptail; /* Final element in the list so far */
size_t npats; /* Number of elements in the list */
len_string *header; /* Code to appear both in any generated header file and
* the top of the generated lexer */
len_string *top; /* Code to appear at the top of the lexer, after the
* header */
lstr_list_t *states; /* The list of states */
len_string *initstate; /* Initial start state */
len_string *prefix; /* A prefix to use for names in the generated lexer. */
FILE *verb; /* An optional file to print verbose information */
len_string *ustate_type; /* The type of the (optional) user state object */
} lexer_lexer_state;
void init_lexer_lexer_state(lexer_lexer_state *st);
typedef struct yy_Moonlime_state Moonlime_state;
Moonlime_state * MoonlimeInit( void * (*alloc)(size_t),
void (*unalloc)(void *) );
void MoonlimeDestroy( Moonlime_state *lexer );
int MoonlimeRead( Moonlime_state *lexer, char *input, size_t len , lexer_lexer_state * data );
#endif