diff options
author | sanine <sanine.not@pm.me> | 2023-01-18 16:55:01 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-18 16:55:01 -0600 |
commit | 21afbb0644edc06fa47d29b847b4958d317b6a60 (patch) | |
tree | b0b59710cf83abc6b0dfc833a3cc835bb18c1127 | |
parent | 5d2e5a312ba73bd48913e9ac5babe1c644997b3e (diff) |
parse param nodesyacc
-rw-r--r-- | yy/kalmia.l | 14 | ||||
-rw-r--r-- | yy/kalmia.y | 43 |
2 files changed, 51 insertions, 6 deletions
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; } +<INITIAL>"param" { + /* param tag */ + return PARAM; +} <INITIAL>"id"/{ATTR} { /* id attribute */ return ID_ATTR; } -<INTIAL>"count"/{ATTR} { +<INITIAL>"count"/{ATTR} { /* count attribute */ return COUNT_ATTR; } +<INITIAL>"name"/{ATTR} { + /* name attribute */ + return NAME_ATTR; +} +<INITIAL>"type"/{ATTR} { + /* type attribute */ + return TYPE_ATTR; +} <INITIAL>[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 <sval> TEXT %token <lval> INTEGER %token <dval> DOUBLE -%token DATE; +%token DATE %token <float_array> FLOAT_ARRAY %type <float_array> float_array %type <float_array> float_array_start %type <float_array> float_array_attributes -%token ID_ATTR COUNT_ATTR +%token PARAM +%type <param> param +%type <param> param_attrs + +%token ID_ATTR COUNT_ATTR NAME_ATTR TYPE_ATTR %type <sval> 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; } ; |