Skip to content

Commit 587dfbe

Browse files
committed
support square and curly brackets
1 parent 240e18d commit 587dfbe

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/fsm.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ typedef struct {
66
int double_quoted;
77
int backticked;
88
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;
914
} fsm_state;
1015
*/
1116

1217

1318
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};
1520
}
1621

1722

@@ -34,9 +39,10 @@ void fsm_feed(fsm_state* state, const char c) {
3439
state->single_quoted = 0;
3540
}
3641
} else if (state->raw_parse_state == 2) {
37-
if (c == '(') {
42+
if (c == '(' || c == '[' || c == '{') {
3843
state->raw_parse_state = 3;
3944
state->raw_dashes = state->raw_dashes_temp;
45+
state->raw_string_token = c;
4046
state->raw_string = 1;
4147
} else if (c == '-') {
4248
state->raw_dashes_temp++;
@@ -49,7 +55,11 @@ void fsm_feed(fsm_state* state, const char c) {
4955
}
5056
} else {
5157
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 == '}') {
5363
state->raw_parse_state = 2;
5464
} else {
5565
// in raw string

src/fsm.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct {
99
int raw_parse_state; // 1: R/r; 2: "/'; 3: (
1010
int raw_dashes; // number of dashes in raw string
1111
int raw_dashes_temp; // used to store number of dashes temporarily while parsing
12+
char raw_string_token;
1213
int raw_string;
1314
} fsm_state;
1415

0 commit comments

Comments
 (0)