jam...@te... wrote:
> Hi All,
>
> I hope this is not off topic, as its not a direct webmin question, but
> certainly is in the
> domain of the sort of problem it would be good if webmin (as a developer
> library
> helped solve). Anyway, caveat aside here is the question.
>
> I have written many scripts that in an automated fashion modify config
> files. I have also
> on occasion had the need to write my little parsers for config files, but
> in general these have
> been used to read the config file and rarely have I made it rewrite out the
> config file. That being said
> I have had the need to do so many times, but I have avoided because the way
> my parsers had been
> written they did not maintain the white-space structure and comments of the
> orignal config file.
> If I would have written the config files back out after making changes to
> them, I would have totally
> lost all tabbing and comments.
>
> All that being said I was wondering:
>
> a) has anyone solved this probably generally in a perl module?
> b) better yet has anyone solved the problem as something that can be
> used in webmin?
> c) what ideas and experience do the webmin developers have with this
> problem?
>
> In a vague way I had the idea of creating two parse trees. The first is
> the AST that is used for doing thing, and querying
> information gathered from the parse phase. The second tree (really not
> sure if it would be called a parse tree) would essentially
> be a chunked up version of the original config which the objects in the AST
> would point to (or would the chunks in the
> this tree point to the objects int he AST or both). Anyway, that is my
> thus far confused approach I have been considering
> but I would really like to hear what other have done and or think.
Generally, in webmin I haven't bother to preserve white-space structure
and comments within blocks that are being modified, because it is just
too hard :) However, if you did want to do that then the best solution
would be to parse the file into a structure that contains all the details
necessary to re-construct it exactly, including the exact line and column of
each token and the details of all comments.
- Jamie
|