Skip to content

Instantly share code, notes, and snippets.

@zengargoyle
Created November 18, 2015 02:05
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 zengargoyle/18152f52ffce7fc03960 to your computer and use it in GitHub Desktop.
Save zengargoyle/18152f52ffce7fc03960 to your computer and use it in GitHub Desktop.
lost in src
podtest.p6 - what i've managed to get working.
pieces.p6 - the code that makes that bit work.
Pod.p6 - the piece i can't seem to figure out how to jam into
World.nqp / Pod.pm and make it work.
Desired: hints!
How do I go about building up an instance of Pod::Data that splits
up the blocks into an array of un-keyed and a hash of keyed and get
the [], {} access working?
# src/Perl6/World.nqp
my $data_past := self.add_constant(
'Array', 'type_new', :nocache, |$*POD_BLOCKS_DATA
);
my $data := self.add_constant(
'Pod::Data', 'type_new',
:blocks($data_past.compile_time_value),
);
# how to build Pod::Data.new(:$unkeyed, :$keyed); ???
self.install_lexical_symbol(
$*UNIT, '$=data',
$data.compile_time_value
);
# src/core/Pod.pm
my class Pod::Block::Data is Pod::Block {
has @.allowed;
}
class Pod::Data {
has @.blocks;
}
# src/Perl6/{Grammar,Actions}.nqp
# basically clone/mutate Pod::Block::Code producers into Pod::Block::Data
# producers and push onto $*POD_BLOCKS_DATE := [] array.
# vim: ts=4 sw=4
class Pod::Data {
has @.blocks;
has @!unkeyed handles <elems AT-POS EXISTS-POS>;
has %!keyed handles <keys AT-KEY EXISTS-KEY>;
method BUILD(:@!blocks) {
for @!blocks -> $block {
# .content is currently Array[Str] with some weirdness due to
# being a copy of =code. should be make to contain a single
# string (most likely). until then, just .join them.
my $contents = $block.contents.join;
if $block.config<key> -> $key {
%!keyed{$key} = $contents;
}
else {
@!unkeyed.push: $contents;
}
}
}
method Str { @!unkeyed.join }
# .gist .perl .????
}
=begin data
un-keyed data block
=end data
=begin data :key<foo>
keyed data block
=end data
say $=data.WHAT;
say $=data.perl;
=begin comment
Produces Output (formatted for readability)
(Pod::Data)
Pod::Data.new(
blocks => [
Pod::Block::Data.new(
allowed => [], config => {},
contents => ["un-keyed data block", "\n"]
),
Pod::Block::Data.new(
allowed => [], config => {:key("foo")},
contents => ["keyed data block", "\n"]
)
]
)
A Pod::Data object bound to $=data containing two Pod::Block::Data objects.
=end comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment