Parse::Stallion

EBNF based regexp backtracking parser and tree evaluator
Download

Parse::Stallion Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Arthur Goldstein
  • Publisher web site:
  • http://search.cpan.org/~arthur/

Parse::Stallion Tags


Parse::Stallion Description

EBNF based regexp backtracking parser and tree evaluator Parse::Stallion is a EBNF-based regexp backtracking parser and tree evaluator.SYNOPSIS use Parse::Stallion; my %rules = (rule_name_1 => ..rule_definition.. , rule_name_2 => ..rule_definition.. , ...); my $stallion = new Parse::Stallion( \%rules, # the following parameters are optional {start_rule => 'rule_name_1', #default the rule which is not a subrule do_evaluation_in_parsing => 0, #default 0 no_evaluation => 0, #default 0 max_steps => 200000, #default 1000000; do_not_compress_eval => 0, #default 0 separator => '__XZ__', #default '__XZ__' need_not_match_whole_string => 0, #default 0 parse_forward => sub {...}, #default no sub parse_backtrack => sub {...}, #default no sub traversal_only => 0, #default 0 unreachable_rules_allowed => 0, #default 0 fast_move_back => 1, #default 1 unless any unevaluation/parse_backtrack }); my $parse_info = {}; # optional, little impact on performance my $parse_hash = {}; # optional, little impact on performance my $parse_trace = []; # optional, some impact on performance my $result = $stallion->parse_and_evaluate($given_string, # usually omit the following {max_steps => 30000, #default from parser's creation parse_info => $parse_info, #if provided, parse info returned parse_trace => $parse_trace, # if provided, trace returned start_position => 0, #default 0 start_rule => $start_rule, # default from parser creation parse_hash => $parse_hash, #used as parse_hash in called routines }); # returns undef if unable to parseRule Definitions (may be abbreviated to first letter): AND('subrule_1', 'subrule_2', ..., EVALUATION(sub{...})) OR('subrule_1', 'subrule_2', ..., EVALUATION(sub{...})) MULTIPLE('subrule_1', EVALUATION(sub{...})) LEAF(qr/regex/, EVALUATION(sub{...}))Stallion parses and evaluates a string using entered grammar rules. The parsing is done top-down via a start rule, in a depth first search forming a parse tree. When a rule does not match the parser backtracks to a node that has another option.For evaluating a tree node, the evaluation subroutine is given a reference to a hash representing the returned values of the child nodes. The evaluation may be done while creating the parse tree and reject a match affecting which strings parse; this allows complex grammars.If the evaluation is not done while parsing, on a successful parse, the tree is evaluated in bottom up, left to right order.The grammars recognized are context free and are similar to those expressed in Extended Backus-Naur Form (EBNF).The object being parsed does not need to be a string. Except for the section on non-strings, the documentation assumes strings are being parsed. Requirements: · Perl


Parse::Stallion Related Software