Skip to content

Commit c8c20c6

Browse files
author
runrevali
committed
[[ StdMlc ]] Various updates and fixes
1 parent 276e5c2 commit c8c20c6

File tree

7 files changed

+289
-223
lines changed

7 files changed

+289
-223
lines changed

libscript/src/bitwise.mlc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This module specifies the syntax definitions and bindings for bitwise operations
44

55
module com.livecode.bitwise
66

7-
public foreign handler MCBitwiseEvalBitwiseAnd(in Left as integer, in Right as integer, out Value as integer) as undefined binds to "<builtin>"
8-
public foreign handler MCBitwiseEvalBitwiseOr(in Left as integer, in Right as integer, out Value as integer) as undefined binds to "<builtin>"
9-
public foreign handler MCBitwiseEvalBitwiseNot(in Operand as integer, out Value as integer) as undefined binds to "<builtin>"
10-
public foreign handler MCBitwiseEvalBitwiseXor(in Left as integer, in Right as integer, out Value as integer) as undefined binds to "<builtin>"
7+
public foreign handler MCBitwiseEvalBitwiseAnd(in Left as int, in Right as int, out Value as int) as undefined binds to "<builtin>"
8+
public foreign handler MCBitwiseEvalBitwiseOr(in Left as int, in Right as int, out Value as int) as undefined binds to "<builtin>"
9+
public foreign handler MCBitwiseEvalBitwiseNot(in Operand as int, out Value as int) as undefined binds to "<builtin>"
10+
public foreign handler MCBitwiseEvalBitwiseXor(in Left as int, in Right as int, out Value as int) as undefined binds to "<builtin>"
1111

12-
public foreign handler MCBitwiseEvalBitwiseShift(in Target as integer, in Shift as integer, out Value as integer) as undefined binds to "<builtin>"
12+
public foreign handler MCBitwiseEvalBitwiseShift(in Target as int, in Shift as int, out Value as int) as undefined binds to "<builtin>"
1313

1414
--
1515

@@ -85,13 +85,6 @@ Summary: Performs a bitwise NOT operation on the binary representation of
8585

8686
Operand: An expression which evaluates to an integer.
8787
output: The integer whose binary representation is the result of the bitwise NOT operation.
88-
89-
Example:
90-
variable tVar as int
91-
put bitwise not (2 * (2^31 - 1)) into tVar -- tVar contains 1
92-
93-
Description:
94-
Each bit of <Left> bitwise or <Right> is 1 if and only if exactly one of the corresponding bits of the binary representation of <Left> and that of <Right> is 1. Otherwise it is 0.
9588
*/
9689

9790
syntax BitwiseNot is prefix operator with precedence 1

libscript/src/byte.mlc

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
This module specifies the syntax definitions and bindings for operations on binary data in modular LiveCode.
2+
This library consists of the operations on bytes included in the standard library of modular LiveCode.
33
*/
44

55
module com.livecode.byte
@@ -53,9 +53,11 @@ Summary: Finds the first or last occurrence of <Needle> within <Targe
5353

5454
Needle: An expression which evaluates to binary data.
5555
Target: An expression which evaluates to binary data.
56-
output: Returns the number of bytes between the first byte of <Target> and the first or last occurrence of <Needle> within <Target>.
57-
Returns 0 if <Needle> does not occur within <Target>.
58-
Searches for first occurrence if neither first nor last is specified.
56+
output: Returns the offset of <Needle> in <Target>.
57+
58+
Description:
59+
The first (respectively last) offset of <Needle> in <Target> is number of bytes between the first byte of <Target> and the first (respectively last) occurrence of <Needle>. If neither first or last is specified, then the first offset is found. If <Needle> does not occur in <Target>, then the output is 0.
60+
5961
*/
6062

6163
syntax ByteOffset is prefix operator with precedence 1
@@ -71,9 +73,10 @@ Summary: Finds the first or last occurrence of <Needle> after a speci
7173
Needle: An expression which evaluates to binary data.
7274
Target: An expression which evaluates to binary data.
7375
After: An expression which evaluates to a valid integer index of Target.
74-
output: Returns the number of bytes between the first byte of <Target> and the first or last occurrence of <Needle> after index <After> in <Target>.
75-
Returns 0 if <Needle> does not occur after index <After> in <Target>.
76-
Searches for first occurrence if neither first nor last is specified.
76+
output: Returns the offset of <Needle> after index <After> in <Target>.
77+
78+
Description:
79+
The first (respectively last) offset of <Needle> in <Target> is number of bytes between byte <After> of <Target> and the first (respectively last) occurrence of <Needle> after <After>. If neither first or last is specified, then the first offset is found. If <Needle> does not occur after <After> in <Target>, then the output is 0.
7780
*/
7881

7982
syntax ByteOffsetAfter is prefix operator with precedence 1
@@ -89,9 +92,10 @@ Summary: Finds the first or last occurrence of <Needle> before a spec
8992
Needle: An expression which evaluates to binary data.
9093
Target: An expression which evaluates to binary data.
9194
After: An expression which evaluates to a valid integer index of Target.
92-
output: Returns the number of bytes between the first byte of <Target> and the first or last occurrence of <Needle> before index <Before> in <Target>.
93-
Returns 0 if <Needle> does not occur before index <Before> in <Target>.
94-
Searches for last occurrence if neither first nor last is specified.
95+
output: Returns the offset of <Needle> before index <Before> in <Target>.
96+
97+
Description:
98+
The first (respectively last) offset of <Needle> in <Target> is number of bytes between the first byte of <Target> and the first (respectively last) occurrence of <Needle> before <Before>. If neither first or last is specified, then the last offset is found. If <Needle> does not occur before <Before> in <Target>, then the output is 0.
9599

96100
*/
97101

@@ -106,6 +110,9 @@ Summary: Determines whether <Needle> is in <Target>.
106110
Needle: An expression which evaluates to a single byte of binary data.
107111
Target: An expression which evaluates to binary data.
108112
output: True if <Needle> is among the bytes of <Target>, and false otherwise.
113+
114+
Description:
115+
>*Note:* It is an error if <Needle> evaluates to data consisting of more than one byte.
109116
*/
110117

111118
syntax IsAmongTheBytesOf is neutral binary operator with precedence 1
@@ -121,6 +128,9 @@ Summary: Determines whether <Needle> contains <Target>.
121128
Needle: An expression which evaluates to binary data.
122129
Target: An expression which evaluates to binary data.
123130
output: True if the bytes of <Needle> occur as a subsequence of the bytes of <Target>, and false otherwise.
131+
132+
Description:
133+
>*Note:* Since the empty data is a subsequence of every sequence of bytes, every sequence of bytes contains the empty data.
124134
*/
125135

126136
syntax ContainsBytes is neutral binary operator with precedence 1
@@ -134,6 +144,9 @@ Summary: Determines whether <Target> begins with <Needle>.
134144
Needle: An expression which evaluates to binary data.
135145
Target: An expression which evaluates to binary data.
136146
output: True if the bytes of <Needle> occur as an initial subsequence of the bytes of <Target>, and false otherwise.
147+
148+
Description:
149+
>*Note:* Since the empty data is an initial subsequence of every sequence of bytes, every sequence of bytes begins with the empty data.
137150
*/
138151

139152
syntax BeginsWithBytes is neutral binary operator with precedence 1
@@ -147,6 +160,9 @@ Summary: Determines whether <Target> ends with <Needle>.
147160
Needle: An expression which evaluates to binary data.
148161
Target: An expression which evaluates to binary data.
149162
output: True if the bytes of <Needle> occur as a final subsequence of the bytes of <Target>, and false otherwise.
163+
164+
Description:
165+
>*Note:* Since the empty data is a final subsequence of every sequence of bytes, every sequence of bytes ends with the empty data.
150166
*/
151167

152168
syntax EndsWithBytes is neutral binary operator with precedence 1
@@ -162,12 +178,13 @@ end syntax
162178
Summary: Designates the byte of data at index <Index> in <Target>.
163179
Index: An expression which evaluates to a valid integer index of <Target>.
164180
Target: An expression which evaluates to binary data.
165-
output: Either locates the byte of data at the given index either for use as the target container of another operation,
166-
or evaluates the byte of data at the given index as the source of another operation.
167181

168-
Example: delete byte 5 of tData // Locates byte 5 and removes it from tData
182+
Example: put the empty data into byte 5 of tData // Locates byte 5 and removes it from tData
169183
Example: get byte 5 of tData // Evaluates byte 5
170184

185+
Description:
186+
Either locates the byte at the given index for use as the target container of another operation, or evaluates the byte at the given index as the source of another operation.
187+
171188
*/
172189

173190
syntax SingletonByteOf is prefix operator with precedence 1
@@ -184,12 +201,13 @@ Summary: Designates the bytes of data between indices <Start> and <Fi
184201
Start: An expression which evaluates to a valid integer index of <Target>.
185202
Finish: An expression which evaluates to a valid integer index of <Target>.
186203
Target: An expression which evaluates to binary data.
187-
output: Either locates the bytes of data between the given indices either for use as the target container of another operation,
188-
or evaluates the bytes of data at the given indices as the source of another operation.
189204

190205
Example: put tBytes into byte 5 to 10 of tData // Locates bytes 5 to 10 and replace them with tBytes
191206
Example: get byte 5 to 10 of tData // Evaluates bytes 5 to 10
192207

208+
Description:
209+
Either locates the bytes between the given indices for use as the target container of another operation, or evaluates the bytes at the given indices as the source of another operation.
210+
193211
*/
194212

195213
syntax RangeByteOf is prefix operator with precedence 1
@@ -201,12 +219,35 @@ end syntax
201219

202220
--
203221

222+
/*
223+
Summary: Designates the location beween byte <Index> - 1 and <Index> of <Target>
224+
225+
Index: An expression which evaluates to a valid integer index of <Target>.
226+
Target: An expression which evaluates to binary data.
227+
228+
Description:
229+
Use with the put statement to insert bytes in the specified location without removal.
230+
231+
*/
232+
204233
syntax BeforeByteOf is prefix operator with precedence 1
205234
"before" "byte" <Index: Expression> "of" <Target: Expression>
206235
begin
207236
StoreBeforeByteOf(input, Index, Target)
208237
end syntax
209238

239+
240+
/*
241+
Summary: Designates the location beween byte <Index> and <Index> + 1 of <Target>
242+
243+
Index: An expression which evaluates to a valid integer index of <Target>.
244+
Target: An expression which evaluates to binary data.
245+
246+
Description:
247+
Use with the put statement to insert bytes in the specified location without removal.
248+
249+
*/
250+
210251
syntax AfterByteOf is prefix operator with precedence 1
211252
"after" "byte" <Index: Expression> "of" <Target: Expression>
212253
begin

libscript/src/char.mlc

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
This library consists of the operations on chars included in the standard library of modular LiveCode.
3+
*/
4+
15
module com.livecode.char
26

37
public foreign handler MCCharFetchCharOf(in Index as index, in Target as string, out Value as string) as undefined binds to "<builtin>"
@@ -16,6 +20,9 @@ public foreign handler MCCharEvalOffsetOfChars(in IsLast as bool, in Needle as s
1620
public foreign handler MCCharEvalOffsetOfCharsBefore(in IsLast as bool, in Needle as string, in Before as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
1721
public foreign handler MCCharEvalOffsetOfCharsAfter(in IsFirst as bool, in Needle as string, in After as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
1822

23+
public foreign handler MCCharEvalBeginsWith(in Source as string, in Prefix as string, out Result as bool) as undefined binds to "<builtin>"
24+
public foreign handler MCCharEvalEndsWith(in Source as string, in Suffix as string, out Result as bool) as undefined binds to "<builtin>"
25+
1926
public foreign handler MCCharEvalNewlineCharacter(out Value as string) as undefined binds to "<builtin>"
2027

2128
public foreign handler MCCharRepeatForEachChar(inout Iterator as optional pointer, out Iterand as string, in Container as string) as bool binds to "<builtin>"
@@ -88,7 +95,7 @@ Example: put tChars into char 5 to 10 of tString // Locates chars 5 to 10 of
8895
Example: get char 5 to 10 of tString // Evaluates chars 5 to 10
8996

9097
Description:
91-
Either locates the chars between the given indices either for use as the target container of another operation, or evaluates the chars at the given indices as the source of another operation.
98+
Either locates the chars between the given indices for use as the target container of another operation, or evaluates the chars at the given indices as the source of another operation.
9299

93100
*/
94101

@@ -119,12 +126,54 @@ end syntax
119126

120127
--
121128

129+
/*
130+
Summary: Designates the location beween char <Index> - 1 and <Index> of <Target>
131+
132+
Index: An expression which evaluates to a valid integer index of <Target>.
133+
Target: An expression which evaluates to a string.
134+
135+
Example:
136+
variable tVar as string
137+
put "This is false" into tVar
138+
put "sentence " before char 6 of tVar -- tVar contains "This sentence is false"
139+
140+
Description:
141+
Use with the put statement to insert a string in the specified location without removal.
142+
143+
*/
144+
122145
syntax BeforeCharOf is prefix operator with precedence 1
123146
"before" "char" <Index: Expression> "of" <Target: Expression>
124147
begin
125148
MCCharStoreBeforeCharOf(input, Index, Target)
126149
end syntax
127150

151+
/*
152+
Summary: Designates the location beween char <Index> and <Index> + 1 of <Target>
153+
154+
Index: An expression which evaluates to a valid integer index of <Target>.
155+
Target: An expression which evaluates to a string.
156+
157+
Example:
158+
variable tVar as string
159+
put "123" into tVar
160+
161+
variable tCount
162+
put the number of chars in tVar into tCount
163+
subtract 1 from tCount
164+
165+
repeat tCount times
166+
put "," after char tCount of tVar
167+
subtract 1 from tCount
168+
end repeat
169+
170+
// tVar contains 1,2,3
171+
172+
Description:
173+
Use with the put statement to insert a string in the specified location without removal.
174+
175+
*/
176+
128177
syntax AfterCharOf is prefix operator with precedence 1
129178
"after" "char" <Index: Expression> "of" <Target: Expression>
130179
begin
@@ -203,12 +252,11 @@ Example:
203252
variable tLastDot as int
204253
variable tAddress as string
205254
variable tTLD as string
206-
put "http://www.livecode.com/index.php" into tAddress
255+
put "http://www.livecode.com/index.html" into tAddress
207256
put the last offset of "." in tAddress into tLastDot
208257
put the offset of "." before tLastDot in tAddress into tVar
209258
put char tVar + 1 to tVar + 3 of tAddress into tTLD -- tTLD contains "com"
210259

211-
212260
Description:
213261
The first (respectively last) offset of <Needle> in <Target> is number of chars between the first char of <Target>, and the first (respectively last) occurrence of <Needle> in the substring of <Target> ending at char <Before> - 1. If neither first or last is specified, then the last offset is found. If <Needle> does not occur in the given substring of <Target>, then the output is 0.
214262

@@ -222,16 +270,20 @@ end syntax
222270

223271

224272
/*
225-
Summary: Determines whether <Needle> contains <Target>.
273+
Summary: Determines whether <Source> contains <Needle>.
226274
Needle: An expression which evaluates to a string.
227275
Target: An expression which evaluates to a string.
228-
output: True if the chars of <Needle> occur as a subsequence of the chars of <Target>, and false otherwise.
276+
output: True if the chars of <Needle> occur as a subsequence of the chars of <Source>, and false otherwise.
277+
278+
Description:
279+
>*Note:* Since "" is a substring of every string, every string contains the empty string.
280+
229281
*/
230282

231283
syntax ContainsChars is neutral binary operator with precedence 1
232-
<Target: Expression> "contains" <Needle: Expression>
284+
<Source: Expression> "contains" <Needle: Expression>
233285
begin
234-
MCCharEvalIsAmongTheCharsOf(Target, Needle, output)
286+
MCCharEvalIsAmongTheCharsOf(Source, Needle, output)
235287
end syntax
236288

237289
--
@@ -240,33 +292,55 @@ end syntax
240292
Summary: Determines whether <Source> begins with <Prefix>
241293
Prefix: An expression which evaluates to a string.
242294
Source: An expression which evaluates to a string.
243-
output: Returns true if the characters in <Prefix> occur at the start of <Source>,
244-
modulo the contextual string options of the current handler.
295+
output: Returns true if <Prefix> is an initial subsequence of the chars of <Source>.
296+
297+
Description:
298+
>*Note:* Since "" is an initial substring of every string, every string begins with the empty string.
299+
245300
*/
246301

247302
syntax BeginsWithString is neutral binary operator with precedence 1
248303
<Source: Expression> "begins" "with" <Prefix: Expression>
249304
begin
250-
//EvalBeginsWith(Source, Prefix, output)
305+
MCCharEvalBeginsWith(Source, Prefix, output)
251306
end syntax
252307

253308
/*
254-
Summary: Determines whether <Source> ends with <Prefix>
255-
Prefix: An expression which evaluates to a string.
309+
Summary: Determines whether <Source> ends with <Suffix>
310+
Suffix: An expression which evaluates to a string.
256311
Source: An expression which evaluates to a string.
257-
output: Returns true if the characters in <Prefix> occur at the end of <Source>,
258-
modulo the contextual string options of the current handler.
259-
*/
312+
output: Returns true if <Suffix> is a final subsequence of the chars of <Source>.
313+
314+
Description:
315+
>*Note:* Since "" is a final substring of every string, every string ends with the empty string.
260316

317+
*/
261318

262319
syntax EndsWithString is neutral binary operator with precedence 1
263320
<Source: Expression> "ends" "with" <Suffix: Expression>
264321
begin
265-
//EvalEndsWith(Source, Suffix, output)
322+
MCCharEvalEndsWith(Source, Suffix, output)
266323
end syntax
267324

268325
--
269326

327+
/*
328+
Summary: The new line character
329+
330+
Example:
331+
variable tList as list
332+
push "line 1" onto tList
333+
push "line 2" onto tList
334+
push "line 3" onto tList
335+
336+
variable tLines as string
337+
combine tList with newline into tLines -- tLines has 3 lines
338+
339+
Description:
340+
Use the <newline> constant to add new lines to a string variable.
341+
342+
*/
343+
270344
syntax NewLineCharacter is expression
271345
"newline"
272346
begin

0 commit comments

Comments
 (0)