This commit is contained in:
anon 2023-11-09 11:04:41 +01:00
commit b9c25435ae
3 changed files with 112 additions and 0 deletions

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
main:
flex -o main.cpp main.l
g++ main.cpp

11
draft.csml Normal file
View File

@ -0,0 +1,11 @@
// DOCTYPE HTML
html {
head {
}
body {
div {
}
}
}

98
main.l Normal file
View File

@ -0,0 +1,98 @@
%{
#include <stdio.h>
#include <stack>
#define ECHOS(s) fwrite(s, strlen(s), 1, yyout)
std::stack<std::string> tag_stack;
std::string tag_candidate = "";
bool push_tag() {
if (tag_candidate == "") {
return false;
}
tag_stack.push(tag_candidate);
ECHOS("<" + tag_stack.top() + ">");
tag_candidate = "";
}
bool pop_tag() {
ECHOS("</" + tag_stack.top() + ">");
tag_stack.pop();
}
/*
q0(.) -> q1
q0(\d) -> q2
q1(\d) -> qe
q2(\d) -> q2
q2(.) -> qe
qe(\d) -> qe
*/
%}
%x HEAD STRING COMMENT COMMENT_MULTILINE
%s BODY
ws [ \t\r\v\f]
wsnl [ \t\r\v\f\n]
%%
<BODY>{
\/\/ {
BEGIN COMMENT;
ECHOS("<!--");
}
\/\* {
BEGIN COMMENT_MULTILINE;
ECHOS("<!--");
}
w+ {
tag_candidate = yytext;
}
\( {
push_tag();
BEGIN HEAD;
}
\{ {
push_tag();
}
\} {
pop_tag();
}
}
<COMMENT,COMMENT_MULTILINE>{
.* {
ECHO;
}
}
<COMMENT>{
\n {
ECHOS("-->");
BEGIN BODY;
}
}
<COMMENT_MULTILINE>{
\n {
ECHO;
}
\*\/ {
ECHOS("-->");
BEGIN BODY;
}
}
<HEAD> {
.* {
ECHO;
}
)[wsnl]{ {
BEGIN BODY;
}
}
%%