1///|
2struct Input[DecodeFunction] {
3 (UInt, Point) -> @bytes.View
read : (UInt
UInt, 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
4 DecodeFunction
decode : type parameter DecodeFunction
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 type FixedArray[A]
FixedArray[UInt
UInt]
23
24///|
25fn (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(
26 UInt
start_byte : UInt
UInt,
27 UInt
old_end_byte : UInt
UInt,
28 UInt
new_end_byte : UInt
UInt,
29 Point
start_point : type Point
Point,
30 Point
old_end_point : type Point
Point,
31 Point
new_end_point : type Point
Point
32) -> type InputEdit FixedArray[UInt]
InputEdit {
33 [
34 UInt
start_byte,
35 UInt
old_end_byte,
36 UInt
new_end_byte,
37 (self : Point) -> UInt
ts_point_row(Point
start_point),
38 (self : Point) -> UInt
ts_point_column(Point
start_point),
39 (self : Point) -> UInt
ts_point_row(Point
old_end_point),
40 (self : Point) -> UInt
ts_point_column(Point
old_end_point),
41 (self : Point) -> UInt
ts_point_row(Point
new_end_point),
42 (self : Point) -> UInt
ts_point_column(Point
new_end_point),
43 ]
44}
45
46///|
47pub 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(
48 Int
start_byte~ : Int
Int,
49 Int
old_end_byte~ : Int
Int,
50 Int
new_end_byte~ : Int
Int,
51 Point
start_point~ : type Point
Point,
52 Point
old_end_point~ : type Point
Point,
53 Point
new_end_point~ : type Point
Point
54) -> type InputEdit FixedArray[UInt]
InputEdit {
55 let UInt
start_byte = (value : Int) -> UInt
int_to_uint(Int
start_byte)
56 let UInt
old_end_byte = (value : Int) -> UInt
int_to_uint(Int
old_end_byte)
57 let UInt
new_end_byte = (value : Int) -> UInt
int_to_uint(Int
new_end_byte)
58 (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(
59 UInt
start_byte, UInt
old_end_byte, UInt
new_end_byte, Point
start_point, Point
old_end_point, Point
new_end_point,
60 )
61}
62
63///|
64struct DecodeResult {
65 Char
code_point : Char
Char
66 Int
bytes_read : Int
Int
67}
68
69///|
70pub 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 {
71 { Char
code_point, Int
bytes_read }
72}
73
74///|
75/// This function signature reads one code point from the given bytes,
76/// returning the number of bytes consumed and the code point.
77/// If the input is invalid, return `None`.
78pub(open) trait 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 {
79 (Self) -> InputEncoding
encoding(type parameter Self
Self) -> enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding = _
80 (@bytes.View) -> DecodeResult?
decode(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) -> struct DecodeResult {
code_point: Char
bytes_read: Int
}
DecodeResult?
81}
82
83///|
84impl 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 {
85 (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)
86 InputEncoding
Custom
87}
88
89///|
90enum InputEncoding {
91 InputEncoding
UTF8
92 InputEncoding
UTF16LE
93 InputEncoding
UTF16BE
94 InputEncoding
Custom
95}
96
97///|
98pub fn enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding::() -> InputEncoding
custom() -> enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding {
99 InputEncoding
Custom
100}
101
102///|
103pub 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 {
104 match @encoding.Encoding
self {
105 @encoding.@encoding.Encoding
UTF8 => InputEncoding
UTF8
106 @encoding.@encoding.Encoding
UTF16LE => InputEncoding
UTF16LE
107 @encoding.@encoding.Encoding
UTF16BE => InputEncoding
UTF16BE
108 }
109}
110
111///|
112pub 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? {
113 (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)
114 DecodeResult?
None
115}
116
117///|
118fn enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding::(self : InputEncoding) -> UInt
to_uint(InputEncoding
self : enum InputEncoding {
UTF8
UTF16LE
UTF16BE
Custom
}
InputEncoding) -> UInt
UInt {
119 match InputEncoding
self {
120 InputEncoding
UTF8 => 0
121 InputEncoding
UTF16LE => 1
122 InputEncoding
UTF16BE => 2
123 InputEncoding
Custom => 3
124 }
125}
126