forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.lcb
More file actions
167 lines (128 loc) · 6.7 KB
/
map.lcb
File metadata and controls
167 lines (128 loc) · 6.7 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright (C) 2014-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
//module com.livecode.map
public foreign handler EvalKeysOf(in Target as array, out Value as list) as undefined binds to "<builtin>"
public foreign handler EvalElementsOf(in Target as array, out Value as list) as undefined binds to "<builtin>"
/*
Not needed if we switch to 'contains' syntax - equivalent to 'the keys of <map> contains <needle>'
otherwise '<needle> is among the elements of the elements of <map>' may be too wordy.
*/
public foreign handler EvalIsAmongTheKeysOfCaseless(in Needle as string, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "<builtin>"
public foreign handler EvalIsAmongTheKeysOfNumeric(in Needle as integer, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "<builtin>"
public foreign handler EvalIsAmongTheKeysOfMatrix(in Needle as list, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "<builtin>"
public foreign handler EvalIsAmongTheElementsOf(in Needle as any, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "<builtin>"
public foreign handler EvalNumberOfElementsIn(in Target as array, out Count as index) as undefined binds to "<builtin>"
/*
Case sensitive map ops / access / storage
To enable this syntax requires underlying map types which distinguish the case sensitive and caseless key maps
Or we pass in a context parameter as for string comparison operations.
public foreign handler EvalIsAmongTheKeysOfCaseSensitive(in Needle as string, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "<builtin>"
public foreign handler FetchElementOfCaseSensitive(in Target as array, in Key as string, out Value as any) as undefined binds to "<builtin>"
public foreign handler StoreElementOfCaseSensitive(in Value as any, inout Target as array, in Key as string) as undefined binds to "<builtin>"
*/
// Case insensitive map access / storage
public foreign handler FetchElementOfCaseless(in Target as array, in Key as string, out Value as any) as undefined binds to "<builtin>"
public foreign handler StoreElementOfCaseless(in Value as any, inout Target as array, in Key as string) as undefined binds to "<builtin>"
// Numeric map element access / storage
public foreign handler FetchElementOfNumeric(in Target as array, in Key as integer, out Value as any) as undefined binds to "<builtin>"
public foreign handler StoreElementOfNumeric(in Value as any, inout Target as array, in Key as integer) as undefined binds to "<builtin>"
// Matrix element access / storage
public foreign handler FetchElementOfMatrix(in Target as array, in Key as array, out Value as any) as undefined binds to "<builtin>"
public foreign handler StoreElementOfMatrix(in Value as any, inout Target as array, in Key as integer) as undefined binds to "<builtin>"
--
/*
Summary: Returns the keys of a map.
Target: An expression which evaluates to a map.
output: A list whose elements are the keys of <Target>.
Note that the list is not ordered in any way.
*/
syntax KeysOf is prefix operator with precedence 1
"the" "keys" "of" <Target: Expression>
begin
EvalKeysOf(Target, output)
end syntax
/*
Summary: Returns the elements of a map.
Target: An expression which evaluates to a map.
output: A list whose elements are the elements of <Target>.
Note that the list is not ordered in any way.
*/
syntax ElementsOf is prefix operator with precedence 1
"the" "elements" "of" <Target: Expression>
begin
EvalElementsOf(Target, output)
end syntax
--
/*
Summary: Returns the number of elements in <Target>
Target: An expression which evaluates to a map.
*/
syntax CountElementsOf is prefix operator with precedence 1
"the" "number" "of" "elements" "in" <Target: Expression>
begin
EvalNumberOfElementsIn(Target, output)
end syntax
--
/*
Summary: Determines if a map has a given key
Needle: An expression which evaluates to an integer, string, or list of integers.
Target: An expression which evaluates to a map.
output: Returns true if <Needle> can be found among the keys of <Target>.
*/
syntax AmongKeysOf is neutral binary operator with precedence 1
<Needle: Expression> "is" ["not" <IsNot=true>] "among" "the" "keys" "of" <Target: Expression>
begin
// EvalIsAmongTheKeysOfCaseSensitive(Needle, IsNot, Target, output)
EvalIsAmongTheKeysOfCaseless(Needle, IsNot, Target, output)
EvalIsAmongTheKeysOfNumeric(Needle, IsNot, Target, output)
EvalIsAmongTheKeysOfMatrix(Needle, IsNot, Target, output)
end syntax
/*
Summary: Determines if a map contains a given element
Needle: Any expression.
Target: An expression which evaluates to a map.
output: Returns true if <Needle> can be found among the elements of <Target>.
*/
syntax AmongElementsOf is neutral binary operator with precedence 1
<Needle: Expression> "is" ["not" <IsNot=true>] "among" "the" "elements" "of" <Target: Expression>
begin
EvalIsAmongTheElementsOf(Needle, IsNot, Target, output)
end syntax
--
/*
Summary: Designates the element with key <Key> in <Target>.
Key: An expression which evaluates to an integer, string, or list of integers.
Target: An expression which evaluates to a map.
output: Either locates the element container with the given key for use as the target
container of another operation, or evaluates the element with the given key
as the source of another operation.
*/
syntax SingletonElementOf is postfix operator with precedence 1
<Target: Expression> "[" <Key: Expression> "]"
begin
// FetchElementOfCaseSensitive(Target, Key, output)
FetchElementOfCaseless(Target, Key, output)
FetchElementOfNumeric(Target, Key, output)
FetchElementOfMatrix(Target, Key, output)
// StoreElementOfCaseSensitive(input, Target, Key)
StoreElementOfCaseless(input, Target, Key)
StoreElementOfNumeric(input, Target, Key)
StoreElementOfMatrix(input, Target, Key)
end syntax
--
syntax EmptyMap is expression
"the" "empty" "map"
begin
MCMapEvalEmpty(output)
end syntax
end module