-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtools.dyalog
131 lines (122 loc) · 4.16 KB
/
tools.dyalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
:Namespace convertionTools
⍝ === VARIABLES ===
L←⎕av[3+⎕io]
_←⍬
_,←'This namespace, "convertionTools", is used to find'
_,←L,'and solve some possible conversion problems.'
_,←L
_,←L,'At the moment it can only find the use of [brackets] in vectors.'
_,←L,'APLX uses A B[i] to mean A (B[i]) in Dyalog.'
_,←L,'When code from APLX is transferred to Dyalog no such translation is '
_,←L,'usually performed and this tool here can help with that.'
_,←L
_,←L,'The program "findBrackets" accepts the name of a program as argument'
_,←L,'and shows where problems are likely to exist.'
_,←L
_,←L,'For example, if line 23 of program "Calc" reads'
_,←L
_,←L,'[23] A+B C[i]'
_,←L
_,←L,'then the tool will show'
_,←L
_,←L,' findBrackets ''Calc'''
_,←L
_,←L,' ∇ #.Calc (1 found)'
_,←L,'[23] A+B C[i]'
_,←L,' ^^^^^^'
_,←L,7⍴' '
_,←L,'If an empty list is given to "findBrackets" then all programs in the'
_,←L,'workspace will be searched. '
_,←L
_,←L,'Note that overlapping matches are not found. If line 23 of the preceding'
_,←L,'example were '
_,←L
_,←L,'[23] A+B C[i] D[j]'
_,←L
_,←L,'then only '
_,←L
_,←L,'[23] A+B C[i] D[j]'
_,←L,' ^^^^^^'
_,←L,'would be found and shown.'
_,←L,'Also, text and comments are NOT searched but it reports problematic lines'
_,←L,'in text following ∆EA:'
_,←L
_,←L,'[24] '''' ∆EA ''A+B C[i]'' '
_,←L,' ^^^^^^'
_,←L
_,←L,'If replacement is required the program "addParens" works the same way: it'
_,←L,'accepts the name of a program or an empty string to mean "all programs". '
_,←L,'But it only changes code, not code in text following ∆EA for example.'
_,←L
_,←L,' addParens ''Calc'''
_,←L
_,←L,' ∇ #.Calc (1 found)'
_,←L,'[23] A+B (C[i])'
_,←L,' ^^^^^^'
_,←L,'1 replacement made. '
_,←L
_,←L,'If the line has overlapping matches like'
_,←L
_,←L,' findBrackets''Calc'''
_,←L
_,←L,' ∇ #.Calc (1 found) '
_,←L,'[23] A+B C[i] D[j] '
_,←L,' ∧∧∧∧∧∧'
_,←L
_,←L,'then "addParens" will do them all'
_,←L
_,←L,' addParens ''Calc'''
_,←L
_,←L,' ∇ #.Calc (1 found)'
_,←L,'[23] A+B (C[i])D[j]'
_,←L,' ^^^^^^ '
_,←L
_,←L,' ∇ #.Calc (1 found)'
_,←L,'[23] A+B (C[i])(D[j])'
_,←L,' ^^^^^^'
_,←L
_,←L
_,←L
_,←L,'NOTE:'
_,←L
_,←L,'For these tools to work you need at least V15 and user commands version 2.12'
_,←L,'To find out which version you are running type'
_,←L
_,←L,' ]version '
_,←L
_,←L,'If your version is not good enough you can do '
_,←L
_,←L,' ]uupdate '
_,←L
_,←L,'To update your tools.'
_,←L
_,←L,'DanB 2016'
_,←L
Describe←_
RBV←'''((?(DEFINE)(?<S>(?>''''(''''''''|[^''''])*''''))(?<noP>(?>(((&S)|[^()])*)))(?<noB>(?>(((&S)|[^][])*)))(?<P>\((?&noP)?(?&P)?(?&noP)?\))(?<B>\[(?&noB)?(?&B)?(?&noB)?\]))(?<item>((?>⍵)|(?>⍺)|(?&S)|(?&P))\s*(?&B)??) *)((?&item) *(?&B))'''
⎕ex¨'L_'
⍝ === End of variables definition ===
(⎕IO ⎕ML ⎕WX)←1 1 3
∇ addParens arg;exp
⍝ Add parentheses around the 1st element with brackets in a vector
exp←RBV,(1+~0∊⍴arg)⊃' -class=3'{⍺ ⍵}' -object=',arg
exp←'locate -pattern -show -exclude=ct -callback=#.convertionTools.prune ',exp,' -replace "\1 (\G)"'
:Repeat ⋄ :Until '0'=1↑⎕RSI[⎕IO]⎕SE.UCMD exp
∇
∇ findBrackets arg;exp
⍝ Find where bracketed expressions involving vectors are found
⎕←'* List of places where parentheses would be needed in code only:'
exp←RBV,(1+~0∊⍴arg)⊃' -class=3'{⍺ ⍵}' -object=',arg
⎕RSI[⎕IO]⎕SE.UCMD'locate -pattern -show -exclude=ct -callback=#.convertionTools.prune ',exp
⎕←2 1⍴''
⎕←'* List of places where parentheses would be needed after ∆EA:'
exp←'''∆EA''''.*?\K',1↓exp
⎕RSI[⎕IO]⎕SE.UCMD'locate -pattern -show -exclude=c -callback=#.convertionTools.prune ',exp
∇
∇ r←prune exp;noun
:If r←3≠#.⎕NC noun←(∧\exp∊⎕A,'abcdefghijklmnopqrstuvwxyz∆⍙',⎕D)/exp
:AndIf 9=⎕NC'#.APLX'
r←~(#.APLX.⎕NC noun)∊3 4
:EndIf
∇
:EndNamespace