From 21afbb0644edc06fa47d29b847b4958d317b6a60 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 18 Jan 2023 16:55:01 -0600 Subject: parse param nodes --- yy/kalmia.l | 14 +++++++++++++- yy/kalmia.y | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-) (limited to 'yy') diff --git a/yy/kalmia.l b/yy/kalmia.l index 7e04f1a..6950330 100644 --- a/yy/kalmia.l +++ b/yy/kalmia.l @@ -49,16 +49,28 @@ ATTR ([\x20\x0a\x0d\x09]*)?"=" /* float_array tag */ return FLOAT_ARRAY; } +"param" { + /* param tag */ + return PARAM; +} "id"/{ATTR} { /* id attribute */ return ID_ATTR; } -"count"/{ATTR} { +"count"/{ATTR} { /* count attribute */ return COUNT_ATTR; } +"name"/{ATTR} { + /* name attribute */ + return NAME_ATTR; +} +"type"/{ATTR} { + /* type attribute */ + return TYPE_ATTR; +} [a-zA-Z_:][a-zA-Z0-9\.\-_:]* { diff --git a/yy/kalmia.y b/yy/kalmia.y index 0d8b16f..48db26e 100644 --- a/yy/kalmia.y +++ b/yy/kalmia.y @@ -19,9 +19,14 @@ struct ka_float_array_t { char *id; - size_t count; + size_t count; /* required */ double *buf; }; + + struct ka_param_t { + char *name; + char *type; /* required */ + }; } %parse-param { struct kalmia_t *result } %code { @@ -38,8 +43,10 @@ } while(0) void kai_abortf_(YYLTYPE *yyllocp, const char *fmt, ...); - /* float arrays */ - int kai_set_float_array_attrs(struct ka_float_array_t *a, char *id, char *count); + /* attribute setters */ + int kai_set_float_array_attrs( + struct ka_float_array_t *a, + char *id, char *count); #define KAI_WRAP(call) \ do { \ @@ -59,6 +66,7 @@ char *sval; char cval; struct ka_float_array_t float_array; + struct ka_param_t param; } %token PROLOG @@ -68,14 +76,18 @@ %token TEXT %token INTEGER %token DOUBLE -%token DATE; +%token DATE %token FLOAT_ARRAY %type float_array %type float_array_start %type float_array_attributes -%token ID_ATTR COUNT_ATTR +%token PARAM +%type param +%type param_attrs + +%token ID_ATTR COUNT_ATTR NAME_ATTR TYPE_ATTR %type attr %% @@ -93,6 +105,7 @@ element: | start_tag end_tag | start_tag content end_tag | float_array + | param ; content: @@ -127,6 +140,7 @@ attribute: ATTR attr { printf("attribute: %s=%s\n", $1, $2); } | ID_ATTR attr | COUNT_ATTR attr + | NAME_ATTR attr ; @@ -165,6 +179,25 @@ float_array_attributes: { KAI_WRAP(kai_set_float_array_attrs(&$$, $2, $4)); } ; + +param: + S_TAG_OPEN PARAM param_attrs EMPTY_TAG_CLOSE + { + $$ = $3; + printf("param[name='%s', type='%s']\n", $$.name, $$.type); + } + ; + +param_attrs: + TYPE_ATTR attr + { $$.name = NULL; $$.type = $2; } + | TYPE_ATTR attr NAME_ATTR attr + { $$.name = $4; $$.type = $2; } + | NAME_ATTR attr TYPE_ATTR attr + { $$.name = $2; $$.type = $4; } + ; + + attr: '=' '"' TEXT '"' { $$ = $3; } ; -- cgit v1.2.1