Regexp::Grammars

Add grammatical parsing features to Perl 5.10 regexes
Download

Regexp::Grammars Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Damian Conway
  • Publisher web site:
  • http://search.cpan.org/~dconway/

Regexp::Grammars Tags


Regexp::Grammars Description

Add grammatical parsing features to Perl 5.10 regexes Regexp::Grammars is a Perl module that adds a small number of new regex constructs that can be used within Perl 5.10 patterns to implement complete recursive-descent parsing.Perl 5.10 already supports recursive=descent matching, via the new (?< name >...) and (?&name) constructs. For example, here is a simple matcher for a subset of the LaTeX markup language: $matcher = qr{ (?&File) (?(DEFINE) (?< File > (?&Element)* ) (?< Element > \s* (?&Command) | \s* (?&Literal) ) (?< Command > \\ \s* (?&Literal) \s* (?&Options)? \s* (?&Args)? ) (?< Options > \) (?< Args > \{ \s* (?&Element)* \s* \} ) (?< Option > \s* + ) (?< Literal > \s* + ) ) }xmsThis technique makes it possible to use regexes to recognize complex, hierarchical--and even recursive--textual structures. The problem is that Perl 5.10 doesn't provide any support for extracting that hierarchical data into nested data structures. In other words, using Perl 5.10 you can match complex data, but not parse it into an internally useful form.An additional problem when using Perl 5.10 regexes to match complex data formats is that you have to make sure you remember to insert whitespace-matching constructs (such as \s*) at every possible position where the data might contain ignorable whitespace. This reduces the readability of such patterns, and increases the chance of errors (typically caused by overlooking a location where whitespace might appear).The Regexp::Grammars module solves both those problems.If you import the module into a particular lexical scope, it preprocesses any regex in that scope, so as to implement a number of extensions to the standard Perl 5.10 regex syntax. These extensions simplify the task of defining and calling subrules within a grammar, and allow those subrule calls to capture and retain the components of they match in a proper hierarchical manner. Requirements: · Perl


Regexp::Grammars Related Software