bsdz wrote:
I am attempting to write a language and need to trace what is
happening in my actions.pm methods.
I have tried writing 2 similar rules based on Squak: -
rule func_def {
'func' <identifier> <parameters>?
...
and
rule func_def2 {
'func' <identifier> <parameters>
...
When I compare the parse tree targets I noticed the first
implementation wraps my <parameters> node into a ResizablePMCArray.
So I am guessing if I leave out parameters in my code then I will
still get an empty $<parameters> key in my $/.
Yes - because you have a quantifier (?) there, you get an array. It will
in this case have either zero or one elements.
So I am wondering if I should test the existence of parameters in my
action.pm with: -
if $<parameters> { ...
This is fine - it gets if the ResizablePMCArray is true, which it is if
it has any elements.
or
if $($<parameters>) > 0 { ...
This is probably an error. If you want to check the number of elements,
put it in array context and numify.
if +@($<parameters>) > 0 { ... }
But what you wrote above is shorter and clearer. BTW, to get the AST, I
would guess you'd want to do $( $<parameters>[0] ).
Is there any way I can get the compiler to send a trace statement to
the console something along the lines of "say $/" or otherwise. I have
noticed a "--trace" option but couldn't find the relevant docs.
--trace=4 may do what you want.
Hope this helps,
Jonathan
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev