Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created July 7, 2011 11:42
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 tadzik/1069339 to your computer and use it in GitHub Desktop.
Save tadzik/1069339 to your computer and use it in GitHub Desktop.
Disappearing .ast
A code: (note lines 243-245, then 262-263)
242 method pod_block:sym<delimited>($/) {
243 say("delimited block from ", $/.from, " to ", $/.to);
244 my $ret := self.any_block($/);
245 say(" became ", $ret);
246 make $ret;
247 }
248
249 method any_block($/) {
250 my $name := $*ST.add_constant('Str', 'str', $<type>.Str);
251 my @children := [];
252 for $<pod_content> {
253 # not trivial, for it can be either an array or a pod node
254 # and we can't really flatten a list in nqp
255 # I hope there's a better way,
256 # but let's settle on this for now
257 if pir::isa($_.ast, 'ResizablePMCArray') {
258 for $_.ast {
259 @children.push($_);
260 }
261 } else {
262 say("a pod block from ", $_.from, " to ", $_.to,
263 " has ast '", $_.ast, "'");
264 @children.push($_.ast);
265 }
266 }
267 my $content := $*ST.add_constant(
268 'Array', 'type_new',
269 |@children,
270 );
271 my $past := $*ST.add_constant(
272 'Pod__Block__Named', 'type_new',
273 :name($name<compile_time_value>),
274 :content($content<compile_time_value>),
275 );
276 return $past<compile_time_value>;
277 }
Output:
delimited block from 26 to 90
became Pod__Block__Named<76962376>
delimited block from 9 to 105
a pod block from 26 to 90 has ast ''
An .ast for block 26-90 has been built, but then it appears to be empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment