forked from 4D-JP/code-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_commands.txt
More file actions
66 lines (60 loc) · 1.89 KB
/
parse_commands.txt
File metadata and controls
66 lines (60 loc) · 1.89 KB
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
If (Is macOS)
$path:=Application file+Folder separator+"Contents"+Folder separator+"Resources"+Folder separator+"gram.4dsyntax"
Else
$path:=Path to object(Application file).parentFolder+"Resources"+Folder separator+"gram.4dsyntax"
End if
$lines:=Split string(Document to text($path);"\r")
$commands:=New object
For ($i;1;$lines.length)
$command:=Command name($i)
If ($command#"") & ($command#"_4D")
$commands[String($i)]:=New object("name";$command;"count";0)
End if
End for
ARRAY TEXT($command_names;0)
OB GET PROPERTY NAMES($commands;$command_names)
$total:=Size of array($command_names)
METHOD GET PATHS(Path all objects;$methods)
$token:="([[:letter:][_]][[:letter:][:number:][. _]]+(?<![. ]))"
$id:=":C(\\d{1,4})"
$motif:="("+$token+$id+")"
$used_commands:=New collection
For ($m;1;Size of array($methods))
$method:=$methods{$m}
If (Current method path#$method)
METHOD GET CODE($method;code;Code with tokens)
$lines:=Split string(code;"\r";sk trim spaces)
$lines.shift()
For each ($line;$lines)
Case of
: (Match regex("\\s*";$line))
: (Match regex("^//.*";$line))
Else
$i:=1
ARRAY LONGINT($pos;0)
ARRAY LONGINT($len;0)
While (Match regex($motif;$line;$i;$pos;$len))
$command:=Substring($line;$pos{3};$len{3})
$command_name:=Substring($line;$pos{2};$len{2})
$command_o:=$commands[$command]
If ($command_o.name=$command_name)
If ($command_o.count=0)
$used_commands.push($command_o)
End if
$command_o.count:=$command_o.count+1
End if
$i:=$pos{1}+$len{1}
End while
End case
End for each
End if
End for
$used_commands:=$used_commands.orderBy("count desc")
C_COLLECTION($col)
$col:=New collection
C_OBJECT($o)
For each ($o;$used_commands)
$ratio:="" //"\t"+string(100*$o.count/$total)
$col.push($o.name+"\t"+String($o.count)+$ratio)
End for each
SET TEXT TO PASTEBOARD($col.join("\r"))