@@ -6,12 +6,17 @@ typedef struct {
6
6
int double_quoted;
7
7
int backticked;
8
8
int escaped;
9
+ int raw_parse_state; // 1: R/r; 2: "/'; 3: (
10
+ int raw_dashes; // number of dashes in raw string
11
+ int raw_dashes_temp; // used to store number of dashes temporarily while parsing
12
+ char raw_string_token;
13
+ int raw_string;
9
14
} fsm_state;
10
15
*/
11
16
12
17
13
18
void fsm_initialize (fsm_state * s ) {
14
- * s = (fsm_state ){0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
19
+ * s = (fsm_state ){0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
15
20
}
16
21
17
22
@@ -34,9 +39,10 @@ void fsm_feed(fsm_state* state, const char c) {
34
39
state -> single_quoted = 0 ;
35
40
}
36
41
} else if (state -> raw_parse_state == 2 ) {
37
- if (c == '(' ) {
42
+ if (c == '(' || c == '[' || c == '{' ) {
38
43
state -> raw_parse_state = 3 ;
39
44
state -> raw_dashes = state -> raw_dashes_temp ;
45
+ state -> raw_string_token = c ;
40
46
state -> raw_string = 1 ;
41
47
} else if (c == '-' ) {
42
48
state -> raw_dashes_temp ++ ;
@@ -49,7 +55,11 @@ void fsm_feed(fsm_state* state, const char c) {
49
55
}
50
56
} else {
51
57
if (state -> raw_parse_state == 3 ) {
52
- if (c == ')' ) {
58
+ if (state -> raw_string_token == '(' && c == ')' ) {
59
+ state -> raw_parse_state = 2 ;
60
+ } else if (state -> raw_string_token == '[' && c == ']' ) {
61
+ state -> raw_parse_state = 2 ;
62
+ } else if (state -> raw_string_token == '{' && c == '}' ) {
53
63
state -> raw_parse_state = 2 ;
54
64
} else {
55
65
// in raw string
0 commit comments