Question about binding in parse


#1
parse x: copy/deep [(-hi-there- 1 2 3 (hello 2 3 4))] function-rule

rule definition:

function-rule: [
   into [
      set code word! (probe code)
      any [integer! | function-rule]
   ]
]

-hi-there-
hello

function-rule: [
   into [
      set code word!
      any [integer! | function-rule]
      (probe code)
   ]
]

hello
hello

The idea is to have code be like it is in the first rule definition. It makes sense as to why this is happening because code is being overshadowed by the inner definition of code so that the probe call is calling the same word twice. Is there a way to set up context-sensitive words that look the same yet print out different results, I know there is in other cases but what about this case?


#2

The more common method of handling this is to use a stack:

stack: []
function-rule: [
   into [
      set code word! (append stack code)
      any [integer! | function-rule]
      (probe take stack)
   ]
]

To do this by manipulating context I believe would be tricky and likely costly.


#3

Yea, that is pretty much the way they introduce a stack is by parsing parentheses. So I guess it is a bad idea to think about context in this situation?


#4

You could potentially force a context solution but in effect I expect you’ll end up with a stack anyway (of contexts) and as @rgchris points out doing so is likely to be costly and tricky (at least right now).

Parse does need something more to make life easier in this regard.