summaryrefslogtreecommitdiff
path: root/yy/kalmia.l
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-01-31 13:01:25 -0600
committersanine <sanine.not@pm.me>2023-01-31 13:01:25 -0600
commitc4933ae58c84edf5a8e8f741dbb49324b1d12787 (patch)
tree7b2366989118ca0757caafce971337256677c0b3 /yy/kalmia.l
parent21afbb0644edc06fa47d29b847b4958d317b6a60 (diff)
begin simplifying parser
Diffstat (limited to 'yy/kalmia.l')
-rw-r--r--yy/kalmia.l77
1 files changed, 19 insertions, 58 deletions
diff --git a/yy/kalmia.l b/yy/kalmia.l
index 6950330..ef7c200 100644
--- a/yy/kalmia.l
+++ b/yy/kalmia.l
@@ -1,7 +1,7 @@
%option noinput nounput noyywrap 8bit nodefault
%option reentrant bison-bridge bison-locations
%option prefix="kalmia"
-%start STRING
+%start STRING TAG
%{
#include <string.h>
@@ -34,91 +34,52 @@ ATTR ([\x20\x0a\x0d\x09]*)?"="
/* xml prologue */
return PROLOG;
}
-<INITIAL>[\x20\x0a\x0d\x09] {
+<INITIAL>[\x20\x0a\x0d\x09] |
+<TAG>[\x20\x0a\x0d\x09] {
/* ignore whitespace */
}
-<INITIAL>"<" { return S_TAG_OPEN; }
-<INITIAL>"</" { return E_TAG_OPEN; }
-<INITIAL>">" { return TAG_CLOSE; }
-<INITIAL>"/>" { return EMPTY_TAG_CLOSE; }
+<INITIAL>"<" { BEGIN(TAG); return S_TAG_OPEN; }
+<INITIAL>"</" { BEGIN(TAG); return E_TAG_OPEN; }
+<TAG>">" { BEGIN(INITIAL); return TAG_CLOSE; }
+<TAG>"/>" { BEGIN(INITIAL); return EMPTY_TAG_CLOSE; }
-<INITIAL>"float_array" {
- /* float_array tag */
- return FLOAT_ARRAY;
-}
-<INITIAL>"param" {
- /* param tag */
- return PARAM;
-}
-
-
-<INITIAL>"id"/{ATTR} {
- /* id attribute */
- return ID_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\.\-_:]* {
+<TAG>[a-zA-Z_:][a-zA-Z0-9\.\-_:]* {
/* generic tag name */
- yylval->sval = strdup(yytext); return NAME;
+ yylval->string = strdup(yytext);
+ return NAME;
}
-<INITIAL>[a-zA-Z_:][a-zA-Z0-9\.\-_:]*/{ATTR} {
+<TAG>[a-zA-Z_:][a-zA-Z0-9\.\-_:]*/{ATTR} {
/* generic attribute key */
- yylval->sval = strdup(yytext);
+ yylval->string = strdup(yytext);
return ATTR;
}
-<INITIAL>"=" {
+<TAG>"=" {
/* attribute "=" */
return *yytext;
}
-
-
-
-<INITIAL>"\"" {
+<TAG>"\"" {
/* begin a string */
BEGIN(STRING);
return *yytext;
}
<STRING>"\"" {
/* end a string */
- BEGIN(INITIAL);
+ BEGIN(TAG);
return *yytext;
}
<STRING>[^"]+ {
/* within a string */
- yylval->sval = strdup(yytext);
+ yylval->string = strdup(yytext);
return TEXT;
}
-<INITIAL>-?[0-9]+ {
- /* integers */
- yylval->lval = strtol(yytext, NULL, 10);
- return INTEGER;
-}
-<INITIAL>-?[0-9]+\.?[0-9]* {
- /* doubles */
- yylval->dval = strtod(yytext, NULL);
- return DOUBLE;
-}
-<INITIAL>{DATE} {
- /* dates */
- return DATE;
+<INITIAL>[^\x20\x0a\x0d\x09<][^<]*[^\x20\x0a\x0d\x09<] {
+ yylval->string = strdup(yytext);
+ return CONTENT;
}