Hello Monks

We have a system that dumps out, for lack of a better term, config files. They don't adhere to any external standard, but are standardized within themselves.

Essentially, I have a colon delimited list of key value pairs:

foo: bar baz: 1234+54q - bar bar who: bob where: October Some other parameter: 42 What are we doing today Brain: Same thing we do every day Pinky

Each "config" file produces the same "keys", while the values change.

I suppose it would be easy enough to use some kind of regex trickery, but I'm really trying to avoid that as it's likely the config file format will change and I want someone who isn't me (or a Perl person for that matter) to be able to update the tool to parse the new format. This is where the idea of a "parsing template" came up. I'd like to be able to do something like:

foo: <string> baz: <number><string><number> who: <name> where: <month> Some other parameter: <int> What are we doing today Brain: <varchar>

I had looked at Marpa::R2 previously for parsing the sudoers file, it was a bit cumbersome and I never could quite get it to work properly (someday... but I have more pressing projects at the moment), and I don't know that a full parser is really necessary, but it does sort of fit the "parse from template" bill...

Does anyone have any better ideas? I'm certainly not married to the idea of using some kind of (EE)BNF for parsing, but it seems like it would be the most direct route to write a tool that can consume arbitrary "parsing templates".

Thanks for the advice


In reply to Parsing an Arbitrary "config" file (based on a "template"?) by three18ti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.