First note that the problem is fundamentally impossible until runtime:
b←×
∇ r←boo;a
[1] :If 1=?2
[2] a←+
[3] :Else
[4] a←⎕NS'b'
[5] :EndIf
[6] r←1 2 a.b 3 4
∇
We cannot know if
boo will use the global name
b or not.
That said, some regex magic can get us most of the way there:
∇ Refs←{ ⍝ Like ⎕REFS but takes ⎕NR and returns vector of vectors
[1] ⍺←0 ⍝ include sys-names?
[2] exSys←~⍺
[3] code←'''[^'']+''|(?:⍝|:(?:End)?Section|:Signature|:Attribute|:Require).*|:\w+'⎕R''⍠1⊢⍵
[4] code←':Access(?:\s+(?:public|private|instance|shared|webmethod|override|overridable))*'⎕R''⍠1⊢code
[5] code←':Implements\s+(?:constructor|destructor|method|trigger)'⎕R''⍠1⊢code
[6] inits←'A-Za-zÀ-ÖØ-Ýß-öø-üþⒶ-Ⓩ∆⍙_',exSys↓'⎕'
[7] sysNss←'⎕SE|⎕THIS|⎕BASE|⎕DMX'
[8] nsIds←'(?:',sysNss,')\.[',inits,']'
[9] code←nsIds'\.?⎕\w+'⎕R'&' ''⍣exSys⊢code
[10] names←'(?:##?|',sysNss,')?(?:\.?',exSys/'(?!⎕)'
[11] names,←'[',inits,'][',inits,'\d]*)+'
[12] list←∪names ⎕S'&'⊢code
[13] {⍵[⍋⍵]}list/⍣exSys⍨'⎕DMX'∘≢¨4↑¨list
[14] }
∇
↑Refs⎕NR'FOO'
#.NS.var
#.NS.var2
FOO
local
local2