Skip to content

Commit 285449b

Browse files
author
runrevali
committed
[[ LC Builder ]] Implement delete/first/last for chunk expressions
1 parent 1d12ca4 commit 285449b

File tree

9 files changed

+720
-2
lines changed

9 files changed

+720
-2
lines changed

libscript/src/array.mlc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public foreign handler MCArrayEvalEmpty(out Value as array) as undefined binds t
3838
public foreign handler MCArrayRepeatForEachElement(inout Iterator as optional pointer, out Iterand as any, in Container as array) as bool binds to "<builtin>"
3939
public foreign handler MCArrayRepeatForEachKey(inout Iterator as optional pointer, out Iterand as string, in Container as array) as bool binds to "<builtin>"
4040

41+
public foreign handler MCArrayDeleteElementOfCaseless(inout Target as array, in Key as string) as undefined binds to "<builtin>"
42+
4143
--
4244

4345
/*
@@ -233,6 +235,33 @@ end syntax
233235

234236
--
235237

238+
/*
239+
240+
Summary: Deletes the element with key <Key> in <Target>.
241+
Index: An expression which evaluates to a string.
242+
Target: An expression which evaluates to an array.
243+
244+
Example:
245+
variable tArray as array
246+
put the empty array into tArray
247+
put "value" into tArray["key"]
248+
249+
delete tArray["key"] -- tArray is the empty array
250+
251+
Description:
252+
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.
253+
254+
Tags: Arrays
255+
*/
256+
257+
syntax DeleteElementOfArray is statement
258+
"delete" <Target: Expression> "[" <Key: Expression> "]"
259+
begin
260+
MCArrayDeleteElementOfCaseless(Target, Key)
261+
end syntax
262+
263+
--
264+
236265
/*
237266

238267
Summary: Designates the array with no elements.

libscript/src/byte.mlc

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public foreign handler MCByteStoreByteRangeOf(in Value as data, in Start as inde
4040

4141
public foreign handler MCByteRepeatForEachByte(inout Iterator as optional pointer, out Iterand as data, in Container as data) as bool binds to "<builtin>"
4242

43+
public foreign handler MCByteFetchFirstByteOf(in Target as data, out Value as data) as undefined binds to "<builtin>"
44+
public foreign handler MCByteStoreFirstByteOf(in Value as data, inout Target as data) as undefined binds to "<builtin>"
45+
46+
public foreign handler MCByteFetchLastByteOf(in Target as data, out Value as data) as undefined binds to "<builtin>"
47+
public foreign handler MCByteStoreLastByteOf(in Value as data, inout Target as data) as undefined binds to "<builtin>"
48+
49+
public foreign handler MCByteExecDeleteByteOf(in Index as index, inout Target as data) as undefined binds to "<builtin>"
50+
public foreign handler MCByteExecDeleteByteRangeOf(in Start as index, in Finish as index, inout Target as data) as undefined binds to "<builtin>"
51+
52+
public foreign handler MCByteExecDeleteLastByteOf(inout Target as data) as undefined binds to "<builtin>"
53+
public foreign handler MCByteExecDeleteFirstByteOf(inout Target as data) as undefined binds to "<builtin>"
54+
4355
--
4456

4557
/*
@@ -251,9 +263,134 @@ begin
251263
MCByteStoreByteRangeOf(input, Start, Finish, Target)
252264
end syntax
253265

266+
/*
267+
268+
Summary: Designates the first byte of data in <Target>.
269+
Target: An expression which evaluates to binary data.
270+
271+
Description:
272+
Either locates the first byte for use as the target container of another operation, or evaluates the first byte as the source of another operation.
273+
274+
>*Note:* It is an error if <Target> is empty.
275+
276+
Tags: Binary
277+
*/
278+
279+
syntax FirstByteOf is prefix operator with precedence 1
280+
"the" "first" "byte" "of" <Target: Expression>
281+
begin
282+
MCByteFetchFirstByteOf(Target, output)
283+
MCByteStoreFirstByteOf(input, Target)
284+
end syntax
285+
286+
/*
287+
288+
Summary: Designates the first byte of data in <Target>.
289+
Target: An expression which evaluates to binary data.
290+
291+
Description:
292+
Either locates the first byte for use as the target container of another operation, or evaluates the first byte as the source of another operation.
293+
294+
>*Note:* It is an error if <Target> is empty.
295+
296+
Tags: Binary
297+
*/
298+
299+
syntax LastByteOf is prefix operator with precedence 1
300+
"the" "last" "byte" "of" <Target: Expression>
301+
begin
302+
MCByteFetchLastByteOf(Target, output)
303+
MCByteStoreLastByteOf(input, Target)
304+
end syntax
305+
306+
--
307+
308+
/*
309+
310+
Summary: Deletes the byte of data at index <Index> in <Target>.
311+
Index: An expression which evaluates to a valid integer index of <Target>.
312+
Target: A container of binary data.
313+
314+
Description:
315+
Replaces the byte at the given index with the empty data.
316+
317+
>*Note:* It is an error if <Index> is out of range.
318+
319+
Tags: Binary
320+
*/
321+
322+
syntax DeleteSingletonByteOf is statement
323+
"delete" "byte" <Index: Expression> "of" <Target: Expression>
324+
begin
325+
MCByteExecDeleteByteOf(Index, Target)
326+
end syntax
327+
328+
/*
329+
330+
Summary: Deletes the bytes of data between indices <Start> and <Finish> in <Target>.
331+
332+
Start: An expression which evaluates to a valid integer index of <Target>.
333+
Finish: An expression which evaluates to a valid integer index of <Target>.
334+
Target: A container of binary data.
335+
336+
Description:
337+
Replaces the bytes between the given indices with the empty data.
338+
339+
>*Note:* It is an error if either <Start> or <Finish> are out of range.
340+
341+
Tags: Binary
342+
*/
343+
344+
syntax DeleteRangeByteOf is statement
345+
"delete" "byte" <Start: Expression> "to" <Finish: Expression> "of" <Target: Expression>
346+
begin
347+
MCByteExecDeleteByteRangeOf(Start, Finish, Target)
348+
end syntax
349+
350+
/*
351+
352+
Summary: Deletes the first byte in <Target>.
353+
Target: A binary data container.
354+
355+
Description:
356+
Replaces the first byte in <Target> with the empty data.
357+
358+
>*Note:* It is an error if <Target> is the empty data.
359+
360+
Tags: Binary
361+
*/
362+
363+
syntax DeleteFirstByteOf is statement
364+
"delete" "the" "first" "byte" "of" <Target: Expression>
365+
begin
366+
MCByteExecDeleteFirstByteOf(Target)
367+
end syntax
368+
369+
370+
/*
371+
372+
Summary: Deletes the last byte in <Target>.
373+
Target: A binary data container.
374+
375+
Description:
376+
Replaces the last byte in <Target> with the empty data.
377+
378+
>*Note:* It is an error if <Target> is the empty data.
379+
380+
Tags: Binary
381+
*/
382+
383+
syntax DeleteLastByteOf is statement
384+
"delete" "the" "last" "byte" "of" <Target: Expression>
385+
begin
386+
MCByteExecDeleteLastByteOf(Target)
387+
end syntax
388+
389+
--
390+
254391
/*
255392
Summary: Repeat over the bytes of some data
256-
Iterand: A binary data container.
393+
Iterand: A container of binary data.
257394

258395
Description:
259396
Use repeat for each to perform an operation on each byte of some data. On each iteration, the <Iterand> will contain the next char of the string being iterated over.

libscript/src/char.mlc

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public foreign handler MCCharEvalNewlineCharacter(out Value as string) as undefi
4444

4545
public foreign handler MCCharRepeatForEachChar(inout Iterator as optional pointer, out Iterand as string, in Container as string) as bool binds to "<builtin>"
4646

47+
public foreign handler MCCharFetchFirstCharOf(in Target as string, out Value as string) as undefined binds to "<builtin>"
48+
public foreign handler MCCharStoreFirstCharOf(in Value as string, inout Target as string) as undefined binds to "<builtin>"
49+
50+
public foreign handler MCCharFetchLastCharOf(in Target as string, out Value as string) as undefined binds to "<builtin>"
51+
public foreign handler MCCharStoreLastCharOf(in Value as string, inout Target as string) as undefined binds to "<builtin>"
52+
53+
public foreign handler MCCharExecDeleteCharOf(in Index as index, inout Target as string) as undefined binds to "<builtin>"
54+
public foreign handler MCCharExecDeleteCharRangeOf(in Start as index, in Finish as index, inout Target as string) as undefined binds to "<builtin>"
55+
56+
public foreign handler MCCharExecDeleteLastCharOf(inout Target as string) as undefined binds to "<builtin>"
57+
public foreign handler MCCharExecDeleteFirstCharOf(inout Target as string) as undefined binds to "<builtin>"
58+
4759
--
4860

4961
/*
@@ -132,6 +144,162 @@ begin
132144
MCCharStoreCharRangeOf(input, Start, Finish, Target)
133145
end syntax
134146

147+
/*
148+
149+
Summary: Designates the first char in <Target>.
150+
Target: An expression which evaluates to a string.
151+
152+
Example:
153+
variable tVar as string
154+
put "char" into tVar
155+
156+
variable tFirst as string
157+
put the last char of tVar into tFirst -- tFirst contains "c"
158+
159+
Description:
160+
Either locates the first char for use as the target container of another operation, or evaluates the first char as the source of another operation.
161+
162+
>*Note:* It is an error if <Target> is empty.
163+
164+
Tags: Strings
165+
*/
166+
167+
syntax FirstCharOf is prefix operator with precedence 1
168+
"the" "first" "char" "of" <Target: Expression>
169+
begin
170+
MCCharFetchFirstCharOf(Target, output)
171+
MCCharStoreFirstCharOf(input, Target)
172+
end syntax
173+
174+
/*
175+
176+
Summary: Designates the last char in <Target>.
177+
Target: An expression which evaluates to a string.
178+
179+
Example:
180+
variable tVar as string
181+
put "char" into tVar
182+
183+
variable tLast as string
184+
put the last char of tVar into tLast -- tLast contains "r"
185+
186+
Description:
187+
Either locates the last char for use as the target container of another operation, or evaluates the last char as the source of another operation.
188+
189+
>*Note:* It is an error if <Target> is empty.
190+
191+
Tags: Strings
192+
*/
193+
194+
syntax LastCharOf is prefix operator with precedence 1
195+
"the" "last" "char" "of" <Target: Expression>
196+
begin
197+
MCCharFetchLastCharOf(Target, output)
198+
MCCharStoreLastCharOf(input, Target)
199+
end syntax
200+
201+
--
202+
203+
/*
204+
205+
Summary: Deletes the char at index <Index> in <Target>.
206+
Index: An expression which evaluates to a valid integer index of <Target>.
207+
Target: A string container.
208+
209+
Example:
210+
variable tVar as string
211+
put "thorough" into tVar
212+
delete char 3 of tVar -- tVar contains "through"
213+
214+
Description:
215+
Replaces the char at the given index with the empty string.
216+
217+
>*Note:* It is an error if <Index> is out of range.
218+
219+
Tags: Strings
220+
*/
221+
222+
syntax DeleteSingletonCharOf is statement
223+
"delete" "char" <Index: Expression> "of" <Target: Expression>
224+
begin
225+
MCCharExecDeleteCharOf(Index, Target)
226+
end syntax
227+
228+
/*
229+
230+
Summary: Deletes the chars between indices <Start> and <Finish> in <Target>.
231+
232+
Start: An expression which evaluates to a valid integer index of <Target>.
233+
Finish: An expression which evaluates to a valid integer index of <Target>.
234+
Target: A string container.
235+
236+
Example:
237+
variable tVar as string
238+
put "surround" into tVar
239+
delete char 2 to 4 of tVar -- tVar contains "sound"
240+
241+
Description:
242+
Replaces the chars between the given indices with the empty string.
243+
244+
>*Note:* It is an error if either <Start> or <Finish> are out of range.
245+
246+
Tags: Strings
247+
*/
248+
249+
syntax DeleteRangeCharOf is statement
250+
"delete" "char" <Start: Expression> "to" <Finish: Expression> "of" <Target: Expression>
251+
begin
252+
MCCharExecDeleteCharRangeOf(Start, Finish, Target)
253+
end syntax
254+
255+
/*
256+
257+
Summary: Deletes the first char in <Target>.
258+
Target: A string container.
259+
260+
Example:
261+
variable tVar as string
262+
put "seven" into tVar
263+
delete the first char of tVar -- tVar contains "even"
264+
265+
Description:
266+
Replaces the first char in <Target> with the empty string.
267+
268+
>*Note:* It is an error if <Target> is the empty string.
269+
270+
Tags: Strings
271+
*/
272+
273+
syntax DeleteFirstCharOf is statement
274+
"delete" "the" "first" "char" "of" <Target: Expression>
275+
begin
276+
MCCharExecDeleteFirstCharOf(Target)
277+
end syntax
278+
279+
/*
280+
281+
Summary: Deletes the last char in <Target>.
282+
Target: A string container.
283+
284+
Example:
285+
variable tVar as string
286+
put "deadliness" into tVar
287+
delete the last char of tVar -- tVar contains "deadlines"
288+
289+
Description:
290+
Replaces the last char in <Target> with the empty string.
291+
292+
>*Note:* It is an error if <Target> is the empty string.
293+
294+
Tags: Strings
295+
*/
296+
297+
syntax DeleteLastCharOf is statement
298+
"delete" "the" "last" "char" "of" <Target: Expression>
299+
begin
300+
MCCharExecDeleteLastCharOf(Target)
301+
end syntax
302+
135303
--
136304

137305
/*

0 commit comments

Comments
 (0)