forked from Orchid/orchid
Basic string and binary processing
- strings are now made of graphemes - char is no longer a literal type - preliminary binary support - added implicit extraction methods for primitives - added explicit extraction method for atoms Nothing has been tested yet
This commit is contained in:
@@ -63,7 +63,6 @@ use crate::Primitive;
|
||||
/// atomic_redirect!(InternalToString, expr_inst);
|
||||
/// atomic_impl!(InternalToString, |Self { expr_inst }: &Self, _|{
|
||||
/// with_lit(expr_inst, |l| Ok(match l {
|
||||
/// Literal::Char(c) => c.to_string(),
|
||||
/// Literal::Uint(i) => i.to_string(),
|
||||
/// Literal::Num(n) => n.to_string(),
|
||||
/// Literal::Str(s) => s.clone(),
|
||||
|
||||
@@ -65,7 +65,6 @@ use crate::write_fn_step;
|
||||
/// /// Convert a literal to a string using Rust's conversions for floats,
|
||||
/// /// chars and uints respectively
|
||||
/// ToString = |x| with_lit(x, |l| Ok(match l {
|
||||
/// Literal::Char(c) => c.to_string(),
|
||||
/// Literal::Uint(i) => i.to_string(),
|
||||
/// Literal::Num(n) => n.to_string(),
|
||||
/// Literal::Str(s) => s.clone(),
|
||||
@@ -147,12 +146,12 @@ macro_rules! define_fn {
|
||||
$crate::write_fn_step!(
|
||||
$name
|
||||
{
|
||||
$( $arg_prev:ident : $typ_prev:ty ),*
|
||||
$( $arg_prev : $typ_prev ),*
|
||||
}
|
||||
[< $name $arg0:upper >]
|
||||
[< $name $arg0:camel >]
|
||||
where $arg0:$typ0 $( = $xname => $parse0 )? ;
|
||||
);
|
||||
$crate::define_fn!(@MIDDLE $xname [< $name $arg0:upper >] ($body)
|
||||
$crate::define_fn!(@MIDDLE $xname [< $name $arg0:camel >] ($body)
|
||||
(
|
||||
$( ($arg_prev: $typ_prev) )*
|
||||
($arg0: $typ0)
|
||||
|
||||
@@ -18,7 +18,10 @@ use crate::interpreted::ExprInst;
|
||||
/// discussed below. The newly bound names (here `s` and `i` before `=`) can
|
||||
/// also receive type annotations.
|
||||
///
|
||||
/// ```
|
||||
/// ```no_run
|
||||
/// // FIXME this is a very old example that wouldn't compile now
|
||||
/// use unicode_segmentation::UnicodeSegmentation;
|
||||
///
|
||||
/// use orchidlang::{write_fn_step, Literal, Primitive};
|
||||
/// use orchidlang::interpreted::Clause;
|
||||
/// use orchidlang::stl::litconv::{with_str, with_uint};
|
||||
@@ -36,8 +39,8 @@ use crate::interpreted::ExprInst;
|
||||
/// CharAt0 { s: String }
|
||||
/// i = x => with_uint(x, Ok);
|
||||
/// {
|
||||
/// if let Some(c) = s.chars().nth(*i as usize) {
|
||||
/// Ok(Clause::P(Primitive::Literal(Literal::Char(c))))
|
||||
/// if let Some(c) = s.graphemes(true).nth(*i as usize) {
|
||||
/// Ok(Literal::Char(c.to_string()).into())
|
||||
/// } else {
|
||||
/// RuntimeError::fail(
|
||||
/// "Character index out of bounds".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user