Hello folks,
I'm trying to develop an html template parser employing Flex & Bison, but now I found a problem and I don't know if surrender, so let's see if you can guide me to the solution (if any).
My idea is, having an html template like:
Quote:
<b><!--MARKUP print (username)--></b>
|
I want to generate the following code:
Quote:
print ("<b>")
print (username)
print ("</b>")
|
In that way modifying the template I can design the web without care about the code (and even the language).
I have a flex file, which I show its core, mytemplate.l:
Quote:
START_COMMENT <!--
END_COMMENT -->
%%
{START_COMMENT}"MARKUP".*{END_COMMENT} {printf ("code: %s\n", yytext);}
{START_COMMENT}.*{END_COMMENT} {printf ("HTML Comment: %s\n", yytext);}
. {printf ("Unknow: %s\n", yytext);}
|
(Here I simplified the code to make only print what it gets, but it returns a token and the text to the bison program).
Now my problem is that I would like to get the unknown characters as an unique string. [using the flex file above, returns char by char all HTML code that is not a comment!].
So, Could it be possible to make a flex rule that gets the HTML code?. It is not necessary to check if HTML code is correct I do it (before parse) using expat. Also there is no need to check the resulted code it will be done by the parser or compiler of the used language.
I know that are a lot of tools that uses this kind of templates in all languages and systems... but I'm just exercising my pour flex&bison skills.
Also, using my current flex file, I have to remove the string "<!--MARKUP" from the beginning and "-->" from the end of returned string to bison... But in reality, if I could manage the HTML code as a flex rule, I could solve that sednding to bison an start Token, the code and and end token.
Any hint or link will be appreciated.
Thanks for reading.