Created
November 22, 2010 22:19
-
-
Save ShimmerFairy/710830 to your computer and use it in GitHub Desktop.
Loopery issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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