Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created November 22, 2010 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShimmerFairy/710830 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/710830 to your computer and use it in GitHub Desktop.
Loopery issues
class Pea {
has $.directive;
has $.blocktype;
has $.contents is rw;
method new($directive, $blocktype, $contents) {
self.bless(*, :$directive, :$blocktype, :$contents);
}
method addline($stuffz) {
$.contents ~= $stuffz;
}
method perl {
"$.directive $.blocktype : $.contents";
}
}
class Greenpea::Document {
has $.document;
has Pea @.parsetree;
method new($document) {
self.bless(*, :$document);
}
# XXX blocks-in-blocks will be weird
method parsefile() {
my @doc = $.document.split("\n");
my $contenttype = "ambient";
for @doc {
GreenGrammar.parse($_, :rule<docline>);
if $/.keys[0] == "directive" {
if $/<directive>.keys[0] == "delimited" {
@.parsetree.push(Pea.new("delimited", $/<directive><delimited><blocktype>, $_));
}
}
elsif $/.keys[0] == "content" {
@.parsetree[*-1].addline($_);
}
}
}
method statefile() {
@.parsetree.perl.join("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment