4
4
* This is the parser that is going to handle parsing regular expressions.
5
5
*/
6
6
typedef struct {
7
+ /** The parser that is currently being used. */
8
+ pm_parser_t * parser ;
9
+
7
10
/** A pointer to the start of the source that we are parsing. */
8
11
const uint8_t * start ;
9
12
@@ -26,22 +29,6 @@ typedef struct {
26
29
void * name_data ;
27
30
} pm_regexp_parser_t ;
28
31
29
- /**
30
- * This initializes a new parser with the given source.
31
- */
32
- static void
33
- pm_regexp_parser_init (pm_regexp_parser_t * parser , const uint8_t * start , const uint8_t * end , bool encoding_changed , const pm_encoding_t * encoding , pm_regexp_name_callback_t name_callback , void * name_data ) {
34
- * parser = (pm_regexp_parser_t ) {
35
- .start = start ,
36
- .cursor = start ,
37
- .end = end ,
38
- .encoding_changed = encoding_changed ,
39
- .encoding = encoding ,
40
- .name_callback = name_callback ,
41
- .name_data = name_data
42
- };
43
- }
44
-
45
32
/**
46
33
* This appends a new string to the list of named captures.
47
34
*/
@@ -650,8 +637,17 @@ pm_regexp_parse_pattern(pm_regexp_parser_t *parser) {
650
637
* groups.
651
638
*/
652
639
PRISM_EXPORTED_FUNCTION bool
653
- pm_regexp_parse (const uint8_t * source , size_t size , bool encoding_changed , const pm_encoding_t * encoding , pm_regexp_name_callback_t name_callback , void * name_data ) {
654
- pm_regexp_parser_t parser ;
655
- pm_regexp_parser_init (& parser , source , source + size , encoding_changed , encoding , name_callback , name_data );
656
- return pm_regexp_parse_pattern (& parser );
640
+ pm_regexp_parse (pm_parser_t * parser , const uint8_t * source , size_t size , pm_regexp_name_callback_t name_callback , void * name_data ) {
641
+ pm_regexp_parser_t regexp_parser = {
642
+ .parser = parser ,
643
+ .start = source ,
644
+ .cursor = source ,
645
+ .end = source + size ,
646
+ .encoding_changed = parser -> encoding_changed ,
647
+ .encoding = parser -> encoding ,
648
+ .name_callback = name_callback ,
649
+ .name_data = name_data
650
+ };
651
+
652
+ return pm_regexp_parse_pattern (& regexp_parser );
657
653
}
0 commit comments