@@ -916,7 +916,9 @@ enum {
916
916
MPC_TYPE_CHECK_WITH = 26 ,
917
917
918
918
MPC_TYPE_SOI = 27 ,
919
- MPC_TYPE_EOI = 28
919
+ MPC_TYPE_EOI = 28 ,
920
+
921
+ MPC_TYPE_SEPBY1 = 29
920
922
};
921
923
922
924
typedef struct { char * m ; } mpc_pdata_fail_t ;
@@ -936,6 +938,7 @@ typedef struct { mpc_parser_t *x; mpc_dtor_t dx; mpc_ctor_t lf; } mpc_pdata_not_
936
938
typedef struct { int n ; mpc_fold_t f ; mpc_parser_t * x ; mpc_dtor_t dx ; } mpc_pdata_repeat_t ;
937
939
typedef struct { int n ; mpc_parser_t * * xs ; } mpc_pdata_or_t ;
938
940
typedef struct { int n ; mpc_fold_t f ; mpc_parser_t * * xs ; mpc_dtor_t * dxs ; } mpc_pdata_and_t ;
941
+ typedef struct { int n ; mpc_fold_t f ; mpc_parser_t * x ; mpc_parser_t * sep ; } mpc_pdata_sepby1 ;
939
942
940
943
typedef union {
941
944
mpc_pdata_fail_t fail ;
@@ -955,6 +958,7 @@ typedef union {
955
958
mpc_pdata_repeat_t repeat ;
956
959
mpc_pdata_and_t and ;
957
960
mpc_pdata_or_t or ;
961
+ mpc_pdata_sepby1 sepby1 ;
958
962
} mpc_pdata_t ;
959
963
960
964
struct mpc_parser_t {
@@ -1221,6 +1225,35 @@ static int mpc_parse_run(mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r, mpc_e
1221
1225
if (j >= MPC_PARSE_STACK_MIN ) { mpc_free (i , results ); });
1222
1226
}
1223
1227
1228
+ case MPC_TYPE_SEPBY1 :
1229
+
1230
+ results = results_stk ;
1231
+
1232
+ if (mpc_parse_run (i , p -> data .sepby1 .x , & results [j ], e , depth + 1 )){
1233
+ j ++ ;
1234
+ results = mpc_grow_results (i , j , results_stk , results );
1235
+
1236
+ while (
1237
+ mpc_parse_run (i , p -> data .sepby1 .sep , & results [j ], e , depth + 1 ) &&
1238
+ mpc_parse_run (i , p -> data .sepby1 .x , & results [j ], e , depth + 1 )
1239
+ ) {
1240
+ j ++ ;
1241
+ results = mpc_grow_results (i , j , results_stk , results );
1242
+ }
1243
+ }
1244
+
1245
+ if (j == 0 ) {
1246
+ MPC_FAILURE (
1247
+ mpc_err_many1 (i , results [j ].error );
1248
+ if (j >= MPC_PARSE_STACK_MIN ) { mpc_free (i , results ); });
1249
+ } else {
1250
+ * e = mpc_err_merge (i , * e , results [j ].error );
1251
+
1252
+ MPC_SUCCESS (
1253
+ mpc_parse_fold (i , p -> data .repeat .f , j , (mpc_val_t * * )results );
1254
+ if (j >= MPC_PARSE_STACK_MIN ) { mpc_free (i , results ); });
1255
+ }
1256
+
1224
1257
case MPC_TYPE_COUNT :
1225
1258
1226
1259
results = p -> data .repeat .n > MPC_PARSE_STACK_MIN
@@ -1268,7 +1301,6 @@ static int mpc_parse_run(mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r, mpc_e
1268
1301
if (p -> data .or .n > MPC_PARSE_STACK_MIN ) { mpc_free (i , results ); });
1269
1302
1270
1303
case MPC_TYPE_AND :
1271
-
1272
1304
if (p -> data .and .n == 0 ) { MPC_SUCCESS (NULL ); }
1273
1305
1274
1306
results = p -> data .or .n > MPC_PARSE_STACK_MIN
@@ -1429,6 +1461,11 @@ static void mpc_undefine_unretained(mpc_parser_t *p, int force) {
1429
1461
mpc_undefine_unretained (p -> data .repeat .x , 0 );
1430
1462
break ;
1431
1463
1464
+ case MPC_TYPE_SEPBY1 :
1465
+ mpc_undefine_unretained (p -> data .sepby1 .x , 0 );
1466
+ mpc_undefine_unretained (p -> data .sepby1 .sep , 0 );
1467
+ break ;
1468
+
1432
1469
case MPC_TYPE_OR : mpc_undefine_or (p ); break ;
1433
1470
case MPC_TYPE_AND : mpc_undefine_and (p ); break ;
1434
1471
@@ -1538,6 +1575,11 @@ mpc_parser_t *mpc_copy(mpc_parser_t *a) {
1538
1575
p -> data .repeat .x = mpc_copy (a -> data .repeat .x );
1539
1576
break ;
1540
1577
1578
+ case MPC_TYPE_SEPBY1 :
1579
+ p -> data .sepby1 .x = mpc_copy (a -> data .sepby1 .x );
1580
+ p -> data .sepby1 .sep = mpc_copy (a -> data .sepby1 .sep );
1581
+ break ;
1582
+
1541
1583
case MPC_TYPE_OR :
1542
1584
p -> data .or .xs = malloc (a -> data .or .n * sizeof (mpc_parser_t * ));
1543
1585
for (i = 0 ; i < a -> data .or .n ; i ++ ) {
@@ -1933,6 +1975,15 @@ mpc_parser_t *mpc_count(int n, mpc_fold_t f, mpc_parser_t *a, mpc_dtor_t da) {
1933
1975
return p ;
1934
1976
}
1935
1977
1978
+ mpc_parser_t * mpc_sepby1 (mpc_fold_t f , mpc_parser_t * sep , mpc_parser_t * a ) {
1979
+ mpc_parser_t * p = mpc_undefined ();
1980
+ p -> type = MPC_TYPE_SEPBY1 ;
1981
+ p -> data .sepby1 .x = a ;
1982
+ p -> data .sepby1 .f = f ;
1983
+ p -> data .sepby1 .sep = sep ;
1984
+ return p ;
1985
+ }
1986
+
1936
1987
mpc_parser_t * mpc_or (int n , ...) {
1937
1988
1938
1989
int i ;
@@ -2120,12 +2171,6 @@ mpc_parser_t *mpc_tok_braces(mpc_parser_t *a, mpc_dtor_t ad) { return mpc_tok_
2120
2171
mpc_parser_t * mpc_tok_brackets (mpc_parser_t * a , mpc_dtor_t ad ) { return mpc_tok_between (a , ad , "{" , "}" ); }
2121
2172
mpc_parser_t * mpc_tok_squares (mpc_parser_t * a , mpc_dtor_t ad ) { return mpc_tok_between (a , ad , "[" , "]" ); }
2122
2173
2123
- mpc_parser_t * mpc_sepby1 (mpc_fold_t f , mpc_parser_t * sep , mpc_parser_t * a ) {
2124
- return mpc_and (2 , f ,
2125
- a , mpc_many (f , mpc_and (2 , mpcf_snd_free , sep , mpc_copy (a ), free )),
2126
- free );
2127
- }
2128
-
2129
2174
/*
2130
2175
** Regular Expression Parsers
2131
2176
*/
@@ -2771,6 +2816,15 @@ static void mpc_print_unretained(mpc_parser_t *p, int force) {
2771
2816
if (p -> type == MPC_TYPE_MANY ) { mpc_print_unretained (p -> data .repeat .x , 0 ); printf ("*" ); }
2772
2817
if (p -> type == MPC_TYPE_MANY1 ) { mpc_print_unretained (p -> data .repeat .x , 0 ); printf ("+" ); }
2773
2818
if (p -> type == MPC_TYPE_COUNT ) { mpc_print_unretained (p -> data .repeat .x , 0 ); printf ("{%i}" , p -> data .repeat .n ); }
2819
+ if (p -> type == MPC_TYPE_SEPBY1 ) {
2820
+ mpc_print_unretained (p -> data .sepby1 .x , 0 );
2821
+ printf (" (" );
2822
+ mpc_print_unretained (p -> data .sepby1 .sep , 0 );
2823
+ printf (" " );
2824
+ mpc_print_unretained (p -> data .sepby1 .x , 0 );
2825
+ printf (")" );
2826
+ printf ("*" );
2827
+ }
2774
2828
2775
2829
if (p -> type == MPC_TYPE_OR ) {
2776
2830
printf ("(" );
@@ -3860,6 +3914,13 @@ static int mpc_nodecount_unretained(mpc_parser_t* p, int force) {
3860
3914
if (p -> type == MPC_TYPE_MANY ) { return 1 + mpc_nodecount_unretained (p -> data .repeat .x , 0 ); }
3861
3915
if (p -> type == MPC_TYPE_MANY1 ) { return 1 + mpc_nodecount_unretained (p -> data .repeat .x , 0 ); }
3862
3916
if (p -> type == MPC_TYPE_COUNT ) { return 1 + mpc_nodecount_unretained (p -> data .repeat .x , 0 ); }
3917
+ if (p -> type == MPC_TYPE_SEPBY1 ) {
3918
+ total = 1 ;
3919
+ total += mpc_nodecount_unretained (p -> data .sepby1 .x , 0 );
3920
+ total += mpc_nodecount_unretained (p -> data .sepby1 .sep , 0 );
3921
+ total += mpc_nodecount_unretained (p -> data .sepby1 .x , 0 );
3922
+ return total ;
3923
+ }
3863
3924
3864
3925
if (p -> type == MPC_TYPE_OR ) {
3865
3926
total = 1 ;
@@ -3907,6 +3968,10 @@ static void mpc_optimise_unretained(mpc_parser_t *p, int force) {
3907
3968
if (p -> type == MPC_TYPE_MANY ) { mpc_optimise_unretained (p -> data .repeat .x , 0 ); }
3908
3969
if (p -> type == MPC_TYPE_MANY1 ) { mpc_optimise_unretained (p -> data .repeat .x , 0 ); }
3909
3970
if (p -> type == MPC_TYPE_COUNT ) { mpc_optimise_unretained (p -> data .repeat .x , 0 ); }
3971
+ if (p -> type == MPC_TYPE_SEPBY1 ) {
3972
+ mpc_optimise_unretained (p -> data .sepby1 .x , 0 );
3973
+ mpc_optimise_unretained (p -> data .sepby1 .sep , 0 );
3974
+ }
3910
3975
3911
3976
if (p -> type == MPC_TYPE_OR ) {
3912
3977
for (i = 0 ; i < p -> data .or .n ; i ++ ) {
0 commit comments