diff --git a/maestro/cdo_sel_parse.c b/maestro/cdo_sel_parse.c index a8612ff82ebce2272e71cd7ef1ecf188618e4fdb..c6f1aa9215996e53817aa83f3e60c16cfca2cb2b 100644 --- a/maestro/cdo_sel_parse.c +++ b/maestro/cdo_sel_parse.c @@ -1429,7 +1429,23 @@ static void pcc_action_value_1(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pc static void pcc_action_value_2(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) { #define auxil (__pcc_ctx->auxil) #define __ (*__pcc_out) -#define i (*__pcc_in->data.leaf.values.buf[2]) +#define n (*__pcc_in->data.leaf.values.buf[2]) +#define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0) +#define _0s ((const)__pcc_in->data.leaf.capt0.range.start) +#define _0e ((const)__pcc_in->data.leaf.capt0.range.end) + __=n; DEBUG("numeric value\n"); +#undef _0e +#undef _0s +#undef _0 +#undef n +#undef __ +#undef auxil +} + +static void pcc_action_value_3(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) { +#define auxil (__pcc_ctx->auxil) +#define __ (*__pcc_out) +#define i (*__pcc_in->data.leaf.values.buf[3]) #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0) #define _0s ((const)__pcc_in->data.leaf.capt0.range.start) #define _0e ((const)__pcc_in->data.leaf.capt0.range.end) @@ -1593,7 +1609,7 @@ static void pcc_action_string_0(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__p __=mstro_csq_val__alloc(MSTRO_CSQ_STRING); __->strval = strdup(_1); if(__->strval==NULL) { - ERR("Failed to allocate string value (for regex) parser node\n"); + ERR("Failed to allocate string value (for string) parser node\n"); abort(); } #undef _1e @@ -1618,7 +1634,7 @@ static void pcc_action_string_1(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__p __=mstro_csq_val__alloc(MSTRO_CSQ_STRING); __->strval = strdup(_2); if(__->strval==NULL) { - ERR("Failed to allocate string value (for regex) parser node\n"); + ERR("Failed to allocate string value (for string) parser node\n"); abort(); } #undef _2e @@ -1631,6 +1647,58 @@ static void pcc_action_string_1(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__p #undef auxil } +static void pcc_action_numeric_val_0(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) { +#define auxil (__pcc_ctx->auxil) +#define __ (*__pcc_out) +#define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0) +#define _0s ((const)__pcc_in->data.leaf.capt0.range.start) +#define _0e ((const)__pcc_in->data.leaf.capt0.range.end) +#define _1 pcc_get_capture_string(__pcc_ctx, __pcc_in->data.leaf.capts.buf[0]) +#define _1s __pcc_in->data.leaf.capts.buf[0]->range.start +#define _1e __pcc_in->data.leaf.capts.buf[0]->range.end + // signed integer, stored as string + __=mstro_csq_val__alloc(MSTRO_CSQ_STRING); + __->strval = strdup(_1); + if(__->strval==NULL) { + ERR("Failed to allocate string value (for integral) parser node\n"); + abort(); + } +#undef _1e +#undef _1s +#undef _1 +#undef _0e +#undef _0s +#undef _0 +#undef __ +#undef auxil +} + +static void pcc_action_numeric_val_1(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) { +#define auxil (__pcc_ctx->auxil) +#define __ (*__pcc_out) +#define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0) +#define _0s ((const)__pcc_in->data.leaf.capt0.range.start) +#define _0e ((const)__pcc_in->data.leaf.capt0.range.end) +#define _2 pcc_get_capture_string(__pcc_ctx, __pcc_in->data.leaf.capts.buf[1]) +#define _2s __pcc_in->data.leaf.capts.buf[1]->range.start +#define _2e __pcc_in->data.leaf.capts.buf[1]->range.end + // exponential notation + __=mstro_csq_val__alloc(MSTRO_CSQ_STRING); + __->strval = strdup(_2); + if(__->strval==NULL) { + ERR("Failed to allocate string value (for exponential numeric) parser node\n"); + abort(); + } +#undef _2e +#undef _2s +#undef _2 +#undef _0e +#undef _0s +#undef _0 +#undef __ +#undef auxil +} + static void pcc_action_space_0(mstro_csq_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) { #define auxil (__pcc_ctx->auxil) #define __ (*__pcc_out) @@ -1658,6 +1726,7 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_regex_i(mstro_csq_context_t *ctx); static pcc_thunk_chunk_t *pcc_evaluate_rule_identifier(mstro_csq_context_t *ctx); static pcc_thunk_chunk_t *pcc_evaluate_rule_simple_regex(mstro_csq_context_t *ctx); static pcc_thunk_chunk_t *pcc_evaluate_rule_string(mstro_csq_context_t *ctx); +static pcc_thunk_chunk_t *pcc_evaluate_rule_numeric_val(mstro_csq_context_t *ctx); static pcc_thunk_chunk_t *pcc_evaluate_rule_space(mstro_csq_context_t *ctx); static pcc_thunk_chunk_t *pcc_evaluate_rule_EOF(mstro_csq_context_t *ctx); @@ -2488,7 +2557,7 @@ L0000:; static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil); chunk->pos = ctx->pos; - pcc_value_table__resize(ctx->auxil, &chunk->values, 3); + pcc_value_table__resize(ctx->auxil, &chunk->values, 4); pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0); { const int p = ctx->pos; @@ -2509,7 +2578,7 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { L0004:; } { - pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_0, 3, 0); + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_0, 4, 0); thunk->data.leaf.values.buf[0] = &(chunk->values.buf[0]); thunk->data.leaf.capt0.range.start = chunk->pos; thunk->data.leaf.capt0.range.end = ctx->pos; @@ -2535,7 +2604,7 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { L0007:; } { - pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_1, 3, 0); + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_1, 4, 0); thunk->data.leaf.values.buf[1] = &(chunk->values.buf[1]); thunk->data.leaf.capt0.range.start = chunk->pos; thunk->data.leaf.capt0.range.end = ctx->pos; @@ -2552,7 +2621,7 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { } L0009:; } - if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, &(chunk->values.buf[2]))) goto L0008; + if (!pcc_apply_rule(ctx, pcc_evaluate_rule_numeric_val, &chunk->thunks, &(chunk->values.buf[2]))) goto L0008; { int i; for (i = 0;; i++) { @@ -2561,7 +2630,7 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { L0010:; } { - pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_2, 3, 0); + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_2, 4, 0); thunk->data.leaf.values.buf[2] = &(chunk->values.buf[2]); thunk->data.leaf.capt0.range.start = chunk->pos; thunk->data.leaf.capt0.range.end = ctx->pos; @@ -2569,6 +2638,32 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_value(mstro_csq_context_t *ctx) { } goto L0001; L0008:; + ctx->pos = p; + pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n); + { + int i; + for (i = 0;; i++) { + if (!pcc_apply_rule(ctx, pcc_evaluate_rule_space, &chunk->thunks, NULL)) goto L0012; + } + L0012:; + } + if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, &(chunk->values.buf[3]))) goto L0011; + { + int i; + for (i = 0;; i++) { + if (!pcc_apply_rule(ctx, pcc_evaluate_rule_space, &chunk->thunks, NULL)) goto L0013; + } + L0013:; + } + { + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_value_3, 4, 0); + thunk->data.leaf.values.buf[3] = &(chunk->values.buf[3]); + thunk->data.leaf.capt0.range.start = chunk->pos; + thunk->data.leaf.capt0.range.end = ctx->pos; + pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk); + } + goto L0001; + L0011:; ctx->pos = p; pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n); goto L0000; @@ -2919,6 +3014,149 @@ L0000:; return NULL; } +static pcc_thunk_chunk_t *pcc_evaluate_rule_numeric_val(mstro_csq_context_t *ctx) { + pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil); + chunk->pos = ctx->pos; + pcc_value_table__resize(ctx->auxil, &chunk->values, 0); + pcc_capture_table__resize(ctx->auxil, &chunk->capts, 2); + { + const int p = ctx->pos; + const int n = chunk->thunks.len; + { + const int p = ctx->pos; + int q; + { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0003; + c = ctx->buffer.buf[ctx->pos]; + if (!( + c == '+' || + c == '-' + )) goto L0003; + ctx->pos++; + } + L0003:; + { + const int p = ctx->pos; + int i; + for (i = 0;; i++) { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0004; + c = ctx->buffer.buf[ctx->pos]; + if (!(c >= '0' && c <= '9')) goto L0004; + ctx->pos++; + } + L0004:; + if (i < 1) { + ctx->pos = p; + goto L0002; + } + } + q = ctx->pos; + chunk->capts.buf[0].range.start = p; + chunk->capts.buf[0].range.end = q; + } + { + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_numeric_val_0, 0, 2); + thunk->data.leaf.capts.buf[0] = &(chunk->capts.buf[0]); + thunk->data.leaf.capt0.range.start = chunk->pos; + thunk->data.leaf.capt0.range.end = ctx->pos; + pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk); + } + goto L0001; + L0002:; + ctx->pos = p; + pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n); + { + const int p = ctx->pos; + int q; + { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0005; + c = ctx->buffer.buf[ctx->pos]; + if (!( + c == '+' || + c == '-' + )) goto L0005; + ctx->pos++; + } + { + int i; + for (i = 0;; i++) { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0006; + c = ctx->buffer.buf[ctx->pos]; + if (!(c >= '0' && c <= '9')) goto L0006; + ctx->pos++; + } + L0006:; + } + if ( + pcc_refill_buffer(ctx, 1) < 1 || + ctx->buffer.buf[ctx->pos] != '.' + ) goto L0005; + ctx->pos++; + { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0005; + c = ctx->buffer.buf[ctx->pos]; + if (!( + c == 'E' || + c == 'e' + )) goto L0005; + ctx->pos++; + } + { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0007; + c = ctx->buffer.buf[ctx->pos]; + if (!( + c == '+' || + c == '-' + )) goto L0007; + ctx->pos++; + } + L0007:; + { + const int p = ctx->pos; + int i; + for (i = 0;; i++) { + char c; + if (pcc_refill_buffer(ctx, 1) < 1) goto L0008; + c = ctx->buffer.buf[ctx->pos]; + if (!(c >= '0' && c <= '9')) goto L0008; + ctx->pos++; + } + L0008:; + if (i < 1) { + ctx->pos = p; + goto L0005; + } + } + q = ctx->pos; + chunk->capts.buf[1].range.start = p; + chunk->capts.buf[1].range.end = q; + } + { + pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_numeric_val_1, 0, 2); + thunk->data.leaf.capts.buf[1] = &(chunk->capts.buf[1]); + thunk->data.leaf.capt0.range.start = chunk->pos; + thunk->data.leaf.capt0.range.end = ctx->pos; + pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk); + } + goto L0001; + L0005:; + ctx->pos = p; + pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n); + goto L0000; + L0001:; + } + return chunk; +L0000:; + pcc_thunk_chunk__destroy(ctx->auxil, chunk); + return NULL; +} + static pcc_thunk_chunk_t *pcc_evaluate_rule_space(mstro_csq_context_t *ctx) { pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil); chunk->pos = ctx->pos; @@ -2994,7 +3232,7 @@ void mstro_csq_destroy(mstro_csq_context_t *ctx) { #define MIN(x,y) ((x)<(y) ? (x) : (y)) -#line 358 "cdo_sel_parse.peg" +#line 370 "cdo_sel_parse.peg" void mstro_csq_val__describe(const struct mstro_csq_val *v, size_t indent) { diff --git a/maestro/cdo_sel_parse.peg b/maestro/cdo_sel_parse.peg index 8918fb0486af94ea7957b1f2027ab0e35d421146..8360d84e731726e0f8172c28d1cacf0d1b4d08b1 100644 --- a/maestro/cdo_sel_parse.peg +++ b/maestro/cdo_sel_parse.peg @@ -294,9 +294,10 @@ attribute_key <- ide:identifier { $$=ide; DEBUG("ide\n"); } # values will be stored as strings and parsed with type info later -value <- space* r:regex space* { $$=r; DEBUG("regex value\n");} - / space* s:string space* { $$=s; DEBUG("string value\n");} - / space* i:identifier space* { $$=i; DEBUG("ide value\n"); } +value <- space* r:regex space* { $$=r; DEBUG("regex value\n");} + / space* s:string space* { $$=s; DEBUG("string value\n");} + / space* n:numeric_val space* { $$=n; DEBUG("numeric value\n");} + / space* i:identifier space* { $$=i; DEBUG("ide value\n"); } regex <- r:regex_i { $$ = r; DEBUG("CI regex\n"); } / r:simple_regex { $$ = r; DEBUG("simple regex\n"); } @@ -337,7 +338,7 @@ string <- ["] < [^"]* > ["] { $$=mstro_csq_val__alloc(MSTRO_CSQ_STRING); $$->strval = strdup($1); if($$->strval==NULL) { - ERR("Failed to allocate string value (for regex) parser node\n"); + ERR("Failed to allocate string value (for string) parser node\n"); abort(); } } @@ -345,12 +346,29 @@ string <- ["] < [^"]* > ["] { $$=mstro_csq_val__alloc(MSTRO_CSQ_STRING); $$->strval = strdup($2); if($$->strval==NULL) { - ERR("Failed to allocate string value (for regex) parser node\n"); + ERR("Failed to allocate string value (for string) parser node\n"); abort(); } } - +numeric_val <- < [+-]?[0-9]+ > { + // signed integer, stored as string + $$=mstro_csq_val__alloc(MSTRO_CSQ_STRING); + $$->strval = strdup($1); + if($$->strval==NULL) { + ERR("Failed to allocate string value (for integral) parser node\n"); + abort(); + } + } + / < [+-][0-9]*[.][Ee][+-]?[0-9]+ > { + // exponential notation + $$=mstro_csq_val__alloc(MSTRO_CSQ_STRING); + $$->strval = strdup($2); + if($$->strval==NULL) { + ERR("Failed to allocate string value (for exponential numeric) parser node\n"); + abort(); + } + } ## isspace() space <- [ \t\n\v\f\r] { ; } @@ -366,7 +384,7 @@ EOF <- !. #define MIN(x,y) ((x)<(y) ? (x) : (y)) -#line 358 "cdo_sel_parse.peg" +#line 370 "cdo_sel_parse.peg" void mstro_csq_val__describe(const struct mstro_csq_val *v, size_t indent) {