The standard library provides simple utilities and data structures for the expression sub-language, and primitive non-terminals for the grammar sub-language.
Note
|
The standard library is under rapid evolution. |
Type | Constructors |
---|---|
|
|
|
|
|
|
|
|
The integer operators are suffixed by the type <int_type>
of their
operands and result type. <int_type>
can be either i8
, u8
,
i16
, u16
, i32
, u32
, i64
, u64
, u
, or i
, where u
and
i
denote usize
and isize
respectively.
Symbol | Signature | Description |
---|---|---|
|
|
Unary minus |
|
|
Boolean negation |
|
|
Bitwise complement |
|
|
Unary integer bitwise complement |
|
|
Binary integer arithmetic operators (add, subtract, multiply, divide) |
|
|
Binary integer bitwise operators (and, or, xor) |
|
|
Binary integer bitwise shift operators (left shift, logical right shift, arithmetic right shift) |
|
|
Integer comparisons (less, less or equal, greater, greater or equal) |
|
|
Binary boolean operators (and, or) |
|
|
Binary bitwise operators (or, and) |
|
|
Operators to check equality (equal, not equal) |
|
|
|
The following modules provide useful operations for the built-in types.
There is a module for each integer type, named after the type with the
initial letter capitalized, e.g. I8
and Usize
for the i8
and
Usize
types respectively. result<t>
denotes t
when the
conversion from source_int_type
to <t>
is possible without loss of
precision (i.e. the numerical integer value remains the same after
conversion), and option<t>
otherwise. The wrapping
conversions
always convert the source value to the result type with wrapping
semantics; here, the numerical integer result value may differ from
the source value. A module does not contain a wrapping
converter
for a source type that always converts safely
(e.g. I16.of_u8_wrapped
does not exist, since it is always possible
to safely convert a u8
into a i16
without change in numerical
value.)
<Int_type>
Value | Signature | Description |
---|---|---|
|
|
integer value of a byte |
|
|
safe string to integer conversion |
|
|
string to integer conversion; throws an exception if conversion fails |
|
|
safe byte vector to integer conversion |
|
|
byte vector to integer conversion; throws an exception if conversion fails |
|
|
safe integer type conversion |
|
|
wrapping integer type conversion |
Byte
Value | Signature | Description |
---|---|---|
|
|
safe integer to byte conversion |
|
|
integer to byte conversion with wrapping semantics |
Bits
Value | Signature | Description |
---|---|---|
|
|
integer value of a bitvector (Bytes are in big-endian order; i.e. the last or rightmost eight bits in the bitvector form the least-significant byte.) |
|
|
integer value of a bitvector with bytes in specified endianness (This is equivalent to |
|
|
boolean value of a bit |
|
|
bit value of a boolean |
|
|
extract the bit from a 1-bitvector |
|
|
put a bit into a 1-bitvector |
|
|
|
|
|
|
List
Value | Signature | Description |
---|---|---|
|
|
head element of list; throws an exception if list is empty |
|
|
tail of list; throws an exception if list is empty |
|
|
list length |
|
|
list concatenation |
|
|
list flattening |
|
|
list reversal |
|
|
mapping over lists |
|
|
mapping over two lists; throws an exception if list lengths are not equal |
|
|
folds an accumulator over a list |
|
|
creates a list containing the specified number of copies of the specified element |
Set
Value | Signature | Description |
---|---|---|
|
|
an empty set |
|
|
add an element to a set |
|
|
check set membership |
Map
Value | Signature | Description |
---|---|---|
|
|
empty map |
|
|
add a key-value binding |
|
|
check if a binding exists for a key |
|
|
return the binding for a key if present |
|
|
return the binding for a key; throws an exception if no binding exists |
String
Value | Signature | Description |
---|---|---|
|
|
empty string |
|
|
string to byte list conversion |
|
|
safe byte vector to string conversion |
|
|
byte vector to string conversion; throws an exception if conversion fails |
|
|
converts a string literal into a string |
Note
|
Character encoding issues for string conversion will be addressed soon. |
View
Value | Signature | Description |
---|---|---|
|
|
gets the current view (i.e. parsing buffer) |
|
|
gets the current view with the cursor set at the beginning of the buffer |
|
|
gets the cursor offset in the specified view (a cursor at the start position has a zero offset) |
|
|
gets the remaining bytes in the specified view (i.e. the number of bytes from the cursor to the end of the view) |
|
|
get the cursor offset in the current view |
|
|
gets the remaining bytes in the current view |
|
|
|
|
|
|
|
|
returns a copy of the view |
The library provides primitive non-terminals, their inherited
attributes if any, and the types of their contents. The byte-valued
non-terminals with an S
suffix return byte lists, and hence compose
with regular expression combinators. The names of the various
*Int*
integer non-terminals indicate signedness (a 'U' prefix
implies unsigned), and bit-width (a NN
suffix indicates the
bit-width).
Non-terminal | Type | Description |
---|---|---|
|
|
Matches a single byte |
|
|
Matches a single ASCII character |
|
|
Matches a single hexadecimal character |
|
|
Matches a single alphanumeric character |
|
|
Matches a single decimal numeric character |
|
|
Matches a single ASCII character |
|
|
Matches a single hexadecimal character |
|
|
Matches a single alphanumeric character |
|
|
Matches a single decimal numeric character |
|
|
Matches a single byte |
|
|
Matches a single byte |
|
|
Matches two bytes |
|
|
Matches two bytes |
|
|
Matches four bytes |
|
|
Matches four bytes |
|
|
Matches eight bytes |
|
|
Matches eight bytes |
|
|
Matches |