I don't think I understand well how javascript variables work in PEG.js. Consider the following:string_1 = &(string_2 {var foo=1;return;}) string_4 {return foo;}string_4 = string_2 string_3The output will be "foo is not defined", isn't it?
Two questions:1. How to put the declaration of foo and returning of its value under one scope?
2. Can we have shadowing of javascript values in inner rules?
2. Can we have shadowing of javascript values in inner rules?No.My overall feel from your example is that you abuse variables for something you should use the match result for. Variables should generally be used only for cases where match results can't.
Generally, I just want to output "1" for the first match, "2" for the second match etc. I don't want to hardcode these numbers because I don't know how many of them to hardcode.Global variables won't help me here due to recursion, i.e. when during a recursion the rule with these local variables is met then I can again increment from "1", something like:
["1","2","3",["1","2","3","4","5","6"],"4"]