sub maybe_new_scope { # if the "enter new scope" rule for the current scope fires then # find a scope whose "can enter" fires # push the scope # fire the "on enter" rule for the new scope my $ruleset = $rulesets{$rulestack[-1]}; my $enter_rule = $ruleset->{maybe_push_scope}; if ( &$enter_rule() ) { print "$rulestack[-1].enter_new_scope true\n" if $DEBUG; foreach my $rulesetname ( keys %rulesets ) { $ruleset = $rulesets{$rulesetname}; my $can_enter_rule = $ruleset->{can_enter}; if ( &$can_enter_rule() ) { print "$rulesetname.can_enter true\n" if $DEBUG; my $on_enter_rule = $ruleset->{on_enter}; &$on_enter_rule(); push @rulestack, $rulesetname; push @indentstack, $indent; } } } return 0; } sub maybe_exit_scope { # if the "exit scope" rule for the current scope fires then # fire the "on exit" rule for the current scope # (pop) my $ruleset = $rulesets{$rulestack[-1]}; my $maybe_exit_rule = $ruleset->{maybe_exit_scope}; if ( &$maybe_exit_rule() ) { print "$rulestack[-1].maybe_exit_scope true\n" if $DEBUG; my $on_exit = $ruleset->{on_exit}; &$on_exit(); $prevtype = 0; # reprime the pump for maybe_emit_markup pop @rulestack; pop @indentstack; return 1; } return 0; }