summaryrefslogtreecommitdiff
path: root/yy/kalmia.l
diff options
context:
space:
mode:
Diffstat (limited to 'yy/kalmia.l')
-rw-r--r--yy/kalmia.l52
1 files changed, 52 insertions, 0 deletions
diff --git a/yy/kalmia.l b/yy/kalmia.l
new file mode 100644
index 0000000..2472bdc
--- /dev/null
+++ b/yy/kalmia.l
@@ -0,0 +1,52 @@
+%{
+#include <stdio.h>
+#include "y.tab.h"
+
+char *copy_str(char *);
+int line_num;
+
+%}
+
+S \x20\x0a\x0d\x09
+DATE [0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[A-Z]*
+
+
+
+
+
+%start STRING
+
+%%
+
+<INITIAL>"<?xml".*"?>" { return PROLOG; }
+
+<INITIAL>[\x20\x0a\x0d\x09] { if (*yytext == '\n') { line_num += 1; } }
+
+
+<INITIAL>"<" { return S_TAG_OPEN; }
+<INITIAL>"</" { return E_TAG_OPEN; }
+<INITIAL>">" { return TAG_CLOSE; }
+<INITIAL>"/>" { return EMPTY_TAG_CLOSE; }
+
+
+<INITIAL>[a-zA-Z_:][a-zA-Z0-9\.\-_:]* { yylval.sval = copy_str(yytext); return NAME; }
+
+<INITIAL>"=" { return *yytext; }
+
+<INITIAL>"\"" { BEGIN(STRING); return *yytext; }
+<STRING>"\"" { BEGIN(INITIAL); return *yytext; }
+<STRING>[^"] { yylval.cval = *yytext; return CHAR; }
+
+<INITIAL>-?[0-9]+ { yylval.lval = strtol(yytext, NULL, 10); return INTEGER; }
+<INITIAL>-?[0-9]+\.?[0-9]* { yylval.dval = strtod(yytext, NULL); return DOUBLE; }
+<INITIAL>{DATE} { return DATE; }
+
+%%
+
+char * copy_str(char *str)
+{
+ size_t len = strlen(str) + 1;
+ char *copy = malloc(sizeof(char) * len);
+ strncpy(copy, str, len);
+ return copy;
+}