-
Notifications
You must be signed in to change notification settings - Fork 16
/
var.eval.fmfn
63 lines (57 loc) · 3.18 KB
/
var.eval.fmfn
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
/*
* =====================================================
* var.eval( contents )
*
* RETURNS: (bool) True or False based on proper evaluation
* DEPENDENCIES: none
* NOTES: Try to always use the List() function when passing multiple values into var.eval!
* $checkScriptName is a reserved local variable used when you wish to enforce
* that inbound parameters match the name of the script. It is reset after the
* evaluation.
* RELEASE: 100909
* =====================================================
*
* This custom function evaluates contents passed as the
* variable declaration part of a Let function. Useful for
* defining global or locally scoped variables.
*
*/
Let( [
$$ERROR.VAR.EVAL = ""; // Reset global error variable for evaluation
var.empty = IsEmpty ( contents ); // test for empty contents
var.semicolons_exist = ( ValueCount ( contents ) = PatternCount ( contents ; ";¶" ) ) or ( ValueCount ( contents ) - 1 = PatternCount ( contents ; ";¶" ) );
var.contents = If ( not var.semicolons_exist ; Substitute ( contents ; ¶ ; ";¶") ; contents ); // Add semicolons if needed
var.trailing_semicolon = Right ( var.contents ; 1 ) = ";"; // Clean off the trailing semicolon if present
var.contents = If ( var.trailing_semicolon; Left ( var.contents ; Length( var.contents ) - 1 ); var.contents );
var.script = Get ( ScriptName );
var.begin = "(" ; // beginning of parameters definition
var.break = "," ; // regular parameters separator (and)
var.end = ")" ; // end of parameters definition
var.parameters = Middle ( var.script ;
Position ( var.script ; var.begin ; 1 ; 1 ) +1;
Position ( var.script ; var.end ; Length ( var.script ) ; -1 ) - Position ( var.script ; var.begin ; 1 ; 1 ) -1
); // raw parameters
// ONLY ALLOWED CHARACTERS FOR SCRIPT NAME PARAMERS ARE THE FOLLOWING (minus the ¶)
var.parameters = Filter ( Substitute ( var.parameters ; var.break ; ¶ ) ; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_¶" );
var.expected = "$" & Substitute ( var.parameters ; ¶ ; "¶$" );
var.matching = FilterValues ( Substitute( var.contents; "="; ¶ ) ; var.expected ); // matching parameters found in ScriptName
var.matching = If ( Right ( var.matching; 1 ) = "¶" ; Left ( var.matching ; Length ( var.matching) - 1) ); // replace extra return added by FilterValues function
var.missingParams = If ( $checkScriptName = True ; var.matching ≠ var.expected ; False )
];
If ( Evaluate( "Let ( [" & var.contents & "]; False )" ) = "?" // generates an error or
or var.empty or var.missingParams; // empty contents or missing expected parameters
// Return error result
Let ( [
$$ERROR.VAR.EVAL =
Case (
var.empty ; "EMPTY PARAMETER SET" ;
var.missingParams ; "MISSING EXPECTED PARAMETERS PER SCRIPT NAME";
List ( "ERROR »"; var.contents )
);
$checkScriptName = "" // reset the $checkScriptName variable (after setting error)
];
False
);
Let ( $checkScriptName = "" ; True )
)
)