P
paktsardines
Hi all,
I am writing a (hopefully) simple parser to parse the contents of a
text file and turn it into some sort of html form. Here's a small
example:
forms.txt contains something like:
# Registration Form
registration {
numcols:2
[heading: Account Details] [ ]
[label:"User Name:"] [textbox:username:amcnab:mandatory]
[label:"First Name:"] [textbox:first_name:Andy]
[label:"Last Name:"] [textbox:last_name:McNab]
[label:"Password:"] [passboxasswd::mandatory]
}
# Error form
error {
numcols:2
[heading:Explosion Error!][]
[label:"Vent Gas?:"] [select:vent:yes|no:no]
}
where:
[.*] denotes an html table cell.
Then, later in my perl code I want to be able to do:
show_form("registration"), or show_form("error") and have it render
the appropriateform layout.
Now, my question is: what is the best way to approach the parsing of
this file? Perhaps more importantly, how can i structure the file to
make the parsing as easy and practical as possible?
Also, can anyone please suggest how to ignore tokens (like ':') that
occur within quoted strings?
Bonus points if your answer makes no reference to lex or yacc.
Thank you for any suggestions!
pakt.
I am writing a (hopefully) simple parser to parse the contents of a
text file and turn it into some sort of html form. Here's a small
example:
forms.txt contains something like:
# Registration Form
registration {
numcols:2
[heading: Account Details] [ ]
[label:"User Name:"] [textbox:username:amcnab:mandatory]
[label:"First Name:"] [textbox:first_name:Andy]
[label:"Last Name:"] [textbox:last_name:McNab]
[label:"Password:"] [passboxasswd::mandatory]
}
# Error form
error {
numcols:2
[heading:Explosion Error!][]
[label:"Vent Gas?:"] [select:vent:yes|no:no]
}
where:
[.*] denotes an html table cell.
Then, later in my perl code I want to be able to do:
show_form("registration"), or show_form("error") and have it render
the appropriateform layout.
Now, my question is: what is the best way to approach the parsing of
this file? Perhaps more importantly, how can i structure the file to
make the parsing as easy and practical as possible?
Also, can anyone please suggest how to ignore tokens (like ':') that
occur within quoted strings?
Bonus points if your answer makes no reference to lex or yacc.
Thank you for any suggestions!
pakt.