I have a funny idea I want to implement, but I don't really know how to start implement it.

It involves taking matches against tree data (that's not too hard to define, it's just regexes with different primitives), and evaluating them on points in the tree (a bit harder?) but not as matches, but as a grammer. The whole thing must be a true parsing solution, that is able to give back twigs of the tree that have matched. This involves backtracking, and nesting, and so on.

On the CPAN there's Data::Match, which seems primitive and unflexible, and a plethora of parsing solutions, which seem very potent, but suited towards strings. For the matching part, I might try to base around Data::Compare which I know and like, but as for the parsing I really don't know...

Is anyone familiar with a parser module to an extent where they can say whether the code can be hijacked to the point that the matching itself, aswell as the input gathering is easily replaceable (that is, the atoms of the grammer and what they are willing to match is my own concern), without having to reimplement the rule composition, backtracking, permuting, and reporting?

Lastly, I would like to be able to prune the search tree based on heuristics. The data can be matched in many ways, i'm concerned about finding one which is good enough, given a user threshold.

-nuffin
zz zZ Z Z #!perl

In reply to Parsing a tree instead of a string? by nothingmuch

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.