more useful options | |
PerlMonks |
Flex, converting regexes, and other Interesting Stuff.by Petruchio (Vicar) |
on Feb 03, 2001 at 20:12 UTC ( [id://56225]=perlquestion: print w/replies, xml ) | Need Help?? |
Petruchio has asked for the wisdom of the Perl Monks concerning the following question:
A few questions for the smart people here. And a story
for the rest of us. ;-) Skip to the end for the
questions. A recent dinner with AgentM and bastard left me with a number of things to ponder, and ideas to try out. One thing I decided was to make my home page more configurable, by offering the stylesheet by CGI, and allowing users to mess with the settings, saving the resulting preferences in a cookie. Rather than write up a form to do this, I wanted to simply provide options for each setting, and have the CGI program automatically generate appropriate form elements. So I considered the format I should use to express possible settings... and I decided that an actual stylesheet would do very well. The "cascading" effect allows you to provide multiple values for each property, for the user agent to regard as being in descending order of importance. All the CGI program would have to do would be to parse a stylesheet, and create a form allowing the user to decide which values would be the first ones. I reached immediately for CSS::Parser, but it didn't seem to be quite the thing; instead of taking in a stylesheet and handing back a tree, it lets you set up callback functions for specific tokens. Perhaps it would actually work, or it contains code I could use, but I moved on. The direction I took was interesting, if not strictly practical. I went to the W3C, looked around the CSS2 spec, and came across a Flex specification for a CSS2 parser. I don't like to flatter myself, but I really am darned Lazy. I thought, "why even consider writing my own parser? Even if perl parsers are very easy, here is an Official Specification. All I have to do is find the program which turns Flex specs into Perl, rather than C, code. I went back to CPAN, and promptly found Parse::Lex and its close bretheren. But on perusing the documentation, I found that it (apparently) didn't deal with Lex/Flex specifications at all, but with Perl stuff... much as Expect.pm doesn't read Expect scripts, but performs a similar function. All the while, by the way, I had the feeling of someone who was wading into deeper and deeper water. Being a non-CS type, I soon reached the point where each step is a jump to get a gulp of air. Next stop: the chatterbox. I waited until there was a respectable showing of local sages, asked a few questions, and was much surprised not to receive answers. So now I'm posting... and I have little doubt that the responses will be very, very interesting. My questions: Is there a means of converting Flex specifications (sans any embedded C code, naturally) into Perl code? If not, I assume it's quite difficult... why is this? Is there a means of turning Flex regular expressions (DFA) into Perl regular expressions (Traditional NFA)? If one wished to make a flex2perl program, I would think this would be necessary. There was a very brief conversation here, when the place was much less well-populated, about the possibility of converting NFA expressions to DFA expressions, by the way. Am I seeing Parse::Lex correctly? Or is it the tool I want after all? Am I seeing CSS::Parser correctly? At this point, I'm interested in the other stuff for its own sake, but this remains a practical point. Yes, I'm sure someone is going to reply with a one-line CSS2 parser. :-) That'll be cool, but not as cool as the education I hope to get from this post.
Back to
Seekers of Perl Wisdom
|
|