rules

Generate the PIR code that matches the various rules we have.

open (RULES,$rulefile) or die "can't read rules file.\n";

$rules = <<'EOH'; # Read in any of the perl6-ian grammars that have been defined for Tcl

.sub "_load_grammar" .local pmc p6rule_compile p6rule_compile = find_global "PGE", "p6rule"

.local string grammar
grammar = "_Tcl_Rules" #xxx should probably not hardcode this.
EOH

my $rule = join("",<RULES>); $rule =~ s/\n//g;

while ($rule =~ m/rule\s+(\w+)\s*{\s*(.*?)\s*};?/g) { my $rule_name = $1; my $rule_def = $2; $rule_def =~ s:\s+: :g; # remove extra whitespace $rule_def =~ s:\\:\\\\:g; $rule_def =~ s:":\\":g;

$rules .= <<EORULE
p6rule_compile("$rule_def", grammar, "$rule_name")
EORULE

};

$rules .= ".end\n";