1///|
2struct Input[DecodeFunction] {
3 read : (UInt, Point) -> @bytes.View
4 decode : DecodeFunction
5}
6
7///|
8pub fn struct Input[DecodeFunction] {
read: (UInt, Point) -> @bytes.View
decode: DecodeFunction
}
Input::(read : (Int, Point) -> @bytes.View, decode : DecodeFunction) -> Input[DecodeFunction]
new[DecodeFunction : trait DecodeFunction {
encoding(Self) -> InputEncoding
decode(@bytes.View) -> DecodeResult?
}
This function signature reads one code point from the given bytes,
returning the number of bytes consumed and the code point.
If the input is invalid, return None.
DecodeFunction](
9 (Int, Point) -> @bytes.View
read : (Int
Int, type Point
Point) -> type @bytes.View
A @bytes.View represents a view into a section of a Bytes without copying the data.
Example
let bs = b"\x00\x01\x02\x03\x04\x05"
let bv = bs[1:4]
assert_eq!(bv.length(), 3)
assert_eq!(bv[0], b'\x01')
assert_eq!(bv[1], b'\x02')
assert_eq!(bv[2], b'\x03')
@bytes.View,
10 DecodeFunction
decode : type parameter DecodeFunction
DecodeFunction
11) -> struct Input[DecodeFunction] {
read: (UInt, Point) -> @bytes.View
decode: DecodeFunction
}
Input[type parameter DecodeFunction
DecodeFunction] {
12 {
13 (UInt, Point) -> @bytes.View
read: fn(UInt
byte, Point
point) {
14 let Int
byte = (value : UInt) -> Int
uint_to_int(UInt
byte)
15 (Int, Point) -> @bytes.View
read(Int
byte, Point
point)
16 },
17 DecodeFunction
decode,
18 }
19}
20
21///|
22type InputEdit FixedArray[UInt]
23
24///|
25extern "js" fn ts_input_edit_new(
26 start_byte : UInt
UInt,
27 old_end_byte : UInt
UInt,
28 new_end_byte : UInt
UInt,
29 start_point : type Point
Point,
30 old_end_point : type Point
Point,
31 new_end_point : type Point
Point
32) -> type InputEdit FixedArray[UInt]
InputEdit =
33 #|(start_byte, old_end_byte, new_end_byte, start_point, old_end_point, new_end_point) => {
34 #| return {
35 #| startPosition: start_point,
36 #| oldEndPosition: old_end_point,
37 #| newEndPosition: new_end_point,
38 #| startIndex: start_byte,
39 #| oldEndIndex: old_end_byte,
40 #| newEndIndex: new_end_byte,
41 #| }
42 #|}
43
44///|
45pub fn type InputEdit FixedArray[UInt]
InputEdit::(start_byte~ : Int, old_end_byte~ : Int, new_end_byte~ : Int, start_point~ : Point, old_end_point~ : Point, new_end_point~ : Point) -> InputEdit
new(
46 Int
start_byte~ : Int
Int,
47 Int
old_end_byte~ : Int
Int,
48 Int
new_end_byte~ : Int
Int,
49 Point
start_point~ : type Point
Point,
50 Point
old_end_point~ : type Point
Point,
51 Point
new_end_point~ : type Point
Point
52) -> type InputEdit FixedArray[UInt]
InputEdit {
53 let UInt
start_byte = (value : Int) -> UInt
int_to_uint(Int
start_byte)
54 let UInt
old_end_byte = (value : Int) -> UInt
int_to_uint(Int
old_end_byte)
55 let UInt
new_end_byte = (value : Int) -> UInt
int_to_uint(Int
new_end_byte)
56 (start_byte : UInt, old_end_byte : UInt, new_end_byte : UInt, start_point : Point, old_end_point : Point, new_end_point : Point) -> InputEdit
ts_input_edit_new(
57 UInt
start_byte, UInt
old_end_byte, UInt
new_end_byte, Point
start_point, Point
old_end_point, Point
new_end_point,
58 )
59}
60
61///|
62struct DecodeResult {
63 code_point : Char
64 bytes_read : Int
65}
66
67///|
68pub fn struct DecodeResult {
code_point: Char
bytes_read: Int
}
DecodeResult::(code_point~ : Char, bytes_read~ : Int) -> DecodeResult
new(Char
code_point~ : Char
Char, Int
bytes_read~ : Int
Int) -> struct DecodeResult {
code_point: Char
bytes_read: Int
}
DecodeResult {
69 { Char
code_point, Int
bytes_read }
70}
71
72///|
73/// This function signature reads one code point from the given bytes,
74/// returning the number of bytes consumed and the code point.
75/// If the input is invalid, return `None`.
76pub(open) trait DecodeFunction {
77 encoding(Self) -> InputEncoding = _
78 decode(@bytes.View) -> DecodeResult?
79}
80
81///|
82impl trait DecodeFunction {
encoding(Self) -> InputEncoding
decode(@bytes.View) -> DecodeResult?
}
This function signature reads one code point from the given bytes,
returning the number of bytes consumed and the code point.
If the input is invalid, return None.
DecodeFunction with (self : Self) -> InputEncoding
encoding(Self
self) -> enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding {
83 (t : Self) -> Unit
Evaluates an expression and discards its result. This is useful when you want
to execute an expression for its side effects but don't care about its return
value, or when you want to explicitly indicate that a value is intentionally
unused.
Parameters:
value : The value to be ignored. Can be of any type.
Example:
test "ignore" {
let x = 42
ignore(x) // Explicitly ignore the value
let mut sum = 0
ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
}
ignore(Self
self)
84 InputEncoding
Custom
85}
86
87///|
88enum InputEncoding {
89 UTF8
90 UTF16LE
91 UTF16BE
92 Custom
93}
94
95///|
96pub fn enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding::() -> InputEncoding
custom() -> enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding {
97 InputEncoding
Custom
98}
99
100///|
101pub impl trait DecodeFunction {
encoding(Self) -> InputEncoding
decode(@bytes.View) -> DecodeResult?
}
This function signature reads one code point from the given bytes,
returning the number of bytes consumed and the code point.
If the input is invalid, return None.
DecodeFunction for enum @encoding.Encoding {
UTF8
UTF16LE
UTF16BE
}
@encoding.Encoding with (self : @encoding.Encoding) -> InputEncoding
encoding(@encoding.Encoding
self) -> enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding {
102 match @encoding.Encoding
self {
103 @encoding.@encoding.Encoding
UTF8 => InputEncoding
UTF8
104 @encoding.@encoding.Encoding
UTF16LE => InputEncoding
UTF16LE
105 @encoding.@encoding.Encoding
UTF16BE => InputEncoding
UTF16BE
106 }
107}
108
109///|
110pub impl trait DecodeFunction {
encoding(Self) -> InputEncoding
decode(@bytes.View) -> DecodeResult?
}
This function signature reads one code point from the given bytes,
returning the number of bytes consumed and the code point.
If the input is invalid, return None.
DecodeFunction for enum @encoding.Encoding {
UTF8
UTF16LE
UTF16BE
}
@encoding.Encoding with (bytes : @bytes.View) -> DecodeResult?
decode(@bytes.View
bytes) -> struct DecodeResult {
code_point: Char
bytes_read: Int
}
DecodeResult? {
111 (t : @bytes.View) -> Unit
Evaluates an expression and discards its result. This is useful when you want
to execute an expression for its side effects but don't care about its return
value, or when you want to explicitly indicate that a value is intentionally
unused.
Parameters:
value : The value to be ignored. Can be of any type.
Example:
test "ignore" {
let x = 42
ignore(x) // Explicitly ignore the value
let mut sum = 0
ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
}
ignore(@bytes.View
bytes)
112 DecodeResult?
None
113}
114
115///|
116fn enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding::(self : InputEncoding) -> UInt
to_uint(InputEncoding
self : enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding) -> UInt
UInt {
117 match InputEncoding
self {
118 InputEncoding
UTF8 => 0
119 InputEncoding
UTF16LE => 1
120 InputEncoding
UTF16BE => 2
121 InputEncoding
Custom => 3
122 }
123}
124