/* 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 . */ //module com.livecode.map public foreign handler EvalKeysOf(in Target as array, out Value as list) as undefined binds to "" public foreign handler EvalElementsOf(in Target as array, out Value as list) as undefined binds to "" /* Not needed if we switch to 'contains' syntax - equivalent to 'the keys of contains ' otherwise ' is among the elements of the elements of ' 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 "" public foreign handler EvalIsAmongTheKeysOfNumeric(in Needle as integer, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "" public foreign handler EvalIsAmongTheKeysOfMatrix(in Needle as list, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "" public foreign handler EvalIsAmongTheElementsOf(in Needle as any, in IsNot as bool, in Target as array, out Result as bool) as undefined binds to "" public foreign handler EvalNumberOfElementsIn(in Target as array, out Count as index) as undefined binds to "" /* 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 "" public foreign handler FetchElementOfCaseSensitive(in Target as array, in Key as string, out Value as any) as undefined binds to "" public foreign handler StoreElementOfCaseSensitive(in Value as any, inout Target as array, in Key as string) as undefined binds to "" */ // 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 "" public foreign handler StoreElementOfCaseless(in Value as any, inout Target as array, in Key as string) as undefined binds to "" // 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 "" public foreign handler StoreElementOfNumeric(in Value as any, inout Target as array, in Key as integer) as undefined binds to "" // Matrix element access / storage public foreign handler FetchElementOfMatrix(in Target as array, in Key as array, out Value as any) as undefined binds to "" public foreign handler StoreElementOfMatrix(in Value as any, inout Target as array, in Key as integer) as undefined binds to "" -- /* Summary: Returns the keys of a map. Target: An expression which evaluates to a map. output: A list whose elements are the keys of . Note that the list is not ordered in any way. */ syntax KeysOf is prefix operator with precedence 1 "the" "keys" "of" 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 . Note that the list is not ordered in any way. */ syntax ElementsOf is prefix operator with precedence 1 "the" "elements" "of" begin EvalElementsOf(Target, output) end syntax -- /* Summary: Returns the number of elements in Target: An expression which evaluates to a map. */ syntax CountElementsOf is prefix operator with precedence 1 "the" "number" "of" "elements" "in" 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 can be found among the keys of . */ syntax AmongKeysOf is neutral binary operator with precedence 1 "is" ["not" ] "among" "the" "keys" "of" 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 can be found among the elements of . */ syntax AmongElementsOf is neutral binary operator with precedence 1 "is" ["not" ] "among" "the" "elements" "of" begin EvalIsAmongTheElementsOf(Needle, IsNot, Target, output) end syntax -- /* Summary: Designates the element with key in . 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 "[" "]" 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