14 my $debug_tree = 1; # show tree while it is built
19 return ' ' x
$tab_depth;
23 print "# $line_number: $line\n";
24 print "# *** $_[0]\n";
32 if @tokens[0] ~~ '#' {
37 # print "<",@tokens[0],"> ";
41 unless defined $line {
42 return shift @post_tokens if @post_tokens;
46 # print "# $line_number: $line\n";
47 @tokens = $line ~~ m
:g
:perl5
{(\w
+|\s
+|.+?
)}; # \b doesn't work ???
48 @tokens = @tokens.map:{ ~$_ }; # force stringify ???
49 # say "tokens: ", @tokens.join('|');
57 next if $word ~~ m
:perl5
/^\s/;
58 unshift @tokens, $word;
64 print tab
(), "sentence(\n" if $debug_tree;
68 #print "# Start sentence\n";
74 print tab
(), ")sentence,\n" if $debug_tree;
79 unshift @tokens, $word;
80 push @ret, [ parenthesis
() ];
84 # print "# start block\n";
85 unshift @tokens, $word;
86 push @ret, [ block
() ];
89 if ( $word ~~ ')' || $word ~~ '}' ) {
90 # print "# end paren|block\n";
91 unshift @tokens, $word;
93 print tab
(), ")sentence,\n" if $debug_tree;
97 print tab
(), "<$word>\n" if $debug_tree;
102 print tab
(), "paren(\n" if $debug_tree;
106 $word ~~ '(' err error
"not a <(> [$word]\n";
111 print tab
(), ")paren,\n" if $debug_tree;
114 unshift @tokens, $word;
115 push @ret, [ sentence
() ];
120 print tab
(), "block{\n" if $debug_tree;
124 # print "token1<$word> ";
125 $word ~~ '{' err error
"not a <{> [$word]\n";
128 # print "token2<$word> ";
129 if $word ~~ m
:perl5
/^(class|method|submethod|sub|multi|macro)$/ {
130 print tab
(), "define(\n" if $debug_tree;
135 if $word ~~ 'multi' {
138 if $word2 ~~ 'method' || $word2 ~~ 'sub' {
139 $word ~= ' ' ~ $word2;
142 push @tokens, $word2;
145 %block<thing
> = $word;
146 print tab
(), "thing = $word,\n" if $debug_tree;
151 %block<namespace_modifier
> = $word;
152 print tab
(), "namespace_modifier = $word,\n" if $debug_tree;
155 unshift @tokens, $word
159 if $word ~~ '(' || $word ~~ '{' {
160 unshift @tokens, $word
163 %block<name
> = $word;
164 print tab
(), "name = $word,\n" if $debug_tree;
168 unshift @tokens, $word;
170 print tab
(), "param = \n" if $debug_tree;
172 %block<param
> = [ parenthesis
() ];
176 #print "<< ", @tokens , " -- $line >>\n";
177 print tab
(), "block = \n" if $debug_tree;
180 %block<block
> = [ block
() ];
185 print tab
(), "}define,\n" if $debug_tree;
189 if ( $word ~~ '}' ) {
190 #print "# End block $tab_depth [$word]\n";
192 print tab
(), "}block,\n" if $debug_tree;
196 if ( $word ~~ '{' ) {
197 # print "# bare block\n";
198 unshift @tokens, $word;
199 push @ret, [ block
() ];
203 if ( $word ~~ m
:perl5
/^\s/ ) {
208 unshift @tokens, $word;
209 push @ret, [ sentence
() ];
217 @post_tokens = ( '}' );
220 my @tree = block
( 'main block' );