diff options
author | sanine <sanine.not@pm.me> | 2023-01-16 13:35:04 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-16 13:35:04 -0600 |
commit | 8d5389d66ef79b58a0fff32fa2b01b4206bfb311 (patch) | |
tree | 02bd7a8c80d5c4897a6e29d5efcccc9ea01082e4 /yy/kalmia.l | |
parent | e7073c34d2ca92663d98bbb1912ad5f6e615e87f (diff) |
add initial parser
Diffstat (limited to 'yy/kalmia.l')
-rw-r--r-- | yy/kalmia.l | 52 |
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; +} |