From c72b0406a32ffc3f04324f7b6c321486762fca41 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 16 Aug 2025 17:21:01 -0400 Subject: Improved parsing and prefix/suffix matching using a `remainder` parameter --- src/environment.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 93b5a16c..3faad24d 100644 --- a/src/environment.c +++ b/src/environment.c @@ -85,14 +85,15 @@ env_t *global_env(bool source_mapping) {"Abort", Type(AbortType), Text("void"), Text("Abort$info"), {}}, {"Memory", Type(MemoryType), Text("Memory_t"), Text("Memory$info"), {}}, {"Bool", Type(BoolType), Text("Bool_t"), Text("Bool$info"), TypedList(ns_entry_t, - {"parse", "Bool$parse", "func(text:Text -> Bool?)"}, + {"parse", "Bool$parse", "func(text:Text, remainder:&Text? = none -> Bool?)"}, )}, {"Byte", Type(ByteType), Text("Byte_t"), Text("Byte$info"), TypedList(ns_entry_t, - {"max", "Byte$max", "Byte"}, {"get_bit", "Byte$get_bit", "func(x:Byte, bit_index:Int -> Bool)"}, {"hex", "Byte$hex", "func(byte:Byte, uppercase=yes, prefix=no -> Text)"}, {"is_between", "Byte$is_between", "func(x:Byte, low:Byte, high:Byte -> Bool)"}, + {"max", "Byte$max", "Byte"}, {"min", "Byte$min", "Byte"}, + {"parse", "Byte$parse", "func(text:Text, remainder:&Text? = none -> Byte?)"}, {"to", "Byte$to", "func(first:Byte, last:Byte, step:Int8?=none -> func(->Byte?))"}, )}, {"Int", Type(BigIntType), Text("Int_t"), Text("Int$info"), TypedList(ns_entry_t, @@ -118,7 +119,7 @@ env_t *global_env(bool source_mapping) {"next_prime", "Int$next_prime", "func(x:Int -> Int)"}, {"octal", "Int$octal", "func(i:Int, digits=0, prefix=yes -> Text)"}, {"onward", "Int$onward", "func(first:Int,step=1 -> func(->Int?))"}, - {"parse", "Int$parse", "func(text:Text -> Int?)"}, + {"parse", "Int$parse", "func(text:Text, remainder:&Text? = none -> Int?)"}, {"plus", "Int$plus", "func(x,y:Int -> Int)"}, {"power", "Int$power", "func(base:Int,exponent:Int -> Int)"}, #if __GNU_MP_VERSION >= 6 @@ -137,7 +138,7 @@ env_t *global_env(bool source_mapping) {"clamped", "Int64$clamped", "func(x,low,high:Int64 -> Int64)"}, {"divided_by", "Int64$divided_by", "func(x,y:Int64 -> Int64)"}, {"gcd", "Int64$gcd", "func(x,y:Int64 -> Int64)"}, - {"parse", "Int64$parse", "func(text:Text -> Int64?)"}, + {"parse", "Int64$parse", "func(text:Text, remainder:&Text? = none -> Int64?)"}, {"get_bit", "Int64$get_bit", "func(x:Int64, bit_index:Int -> Bool)"}, {"hex", "Int64$hex", "func(i:Int64, digits=0, uppercase=yes, prefix=yes -> Text)"}, {"is_between", "Int64$is_between", "func(x:Int64,low:Int64,high:Int64 -> Bool)"}, @@ -159,7 +160,7 @@ env_t *global_env(bool source_mapping) {"clamped", "Int32$clamped", "func(x,low,high:Int32 -> Int32)"}, {"divided_by", "Int32$divided_by", "func(x,y:Int32 -> Int32)"}, {"gcd", "Int32$gcd", "func(x,y:Int32 -> Int32)"}, - {"parse", "Int32$parse", "func(text:Text -> Int32?)"}, + {"parse", "Int32$parse", "func(text:Text, remainder:&Text? = none -> Int32?)"}, {"get_bit", "Int32$get_bit", "func(x:Int32, bit_index:Int -> Bool)"}, {"hex", "Int32$hex", "func(i:Int32, digits=0, uppercase=yes, prefix=yes -> Text)"}, {"is_between", "Int32$is_between", "func(x:Int32,low:Int32,high:Int32 -> Bool)"}, @@ -181,7 +182,7 @@ env_t *global_env(bool source_mapping) {"clamped", "Int16$clamped", "func(x,low,high:Int16 -> Int16)"}, {"divided_by", "Int16$divided_by", "func(x,y:Int16 -> Int16)"}, {"gcd", "Int16$gcd", "func(x,y:Int16 -> Int16)"}, - {"parse", "Int16$parse", "func(text:Text -> Int16?)"}, + {"parse", "Int16$parse", "func(text:Text, remainder:&Text? = none -> Int16?)"}, {"get_bit", "Int16$get_bit", "func(x:Int16, bit_index:Int -> Bool)"}, {"hex", "Int16$hex", "func(i:Int16, digits=0, uppercase=yes, prefix=yes -> Text)"}, {"is_between", "Int16$is_between", "func(x:Int16,low:Int16,high:Int16 -> Bool)"}, @@ -203,7 +204,7 @@ env_t *global_env(bool source_mapping) {"clamped", "Int8$clamped", "func(x,low,high:Int8 -> Int8)"}, {"divided_by", "Int8$divided_by", "func(x,y:Int8 -> Int8)"}, {"gcd", "Int8$gcd", "func(x,y:Int8 -> Int8)"}, - {"parse", "Int8$parse", "func(text:Text -> Int8?)"}, + {"parse", "Int8$parse", "func(text:Text, remainder:&Text? = none -> Int8?)"}, {"get_bit", "Int8$get_bit", "func(x:Int8, bit_index:Int -> Bool)"}, {"hex", "Int8$hex", "func(i:Int8, digits=0, uppercase=yes, prefix=yes -> Text)"}, {"is_between", "Int8$is_between", "func(x:Int8,low:Int8,high:Int8 -> Bool)"}, @@ -238,7 +239,7 @@ env_t *global_env(bool source_mapping) {"INF", "(Num_t)(INFINITY)", "Num"}, {"TAU", "(Num_t)(2.*M_PI)", "Num"}, {"mix", "Num$mix", "func(amount,x,y:Num -> Num)"}, - {"parse", "Num$parse", "func(text:Text -> Num?)"}, + {"parse", "Num$parse", "func(text:Text, remainder:&Text? = none -> Num?)"}, {"abs", "fabs", "func(n:Num -> Num)"}, F_opt(acos), F_opt(acosh), F_opt(asin), F(asinh), F(atan), F_opt(atanh), F(cbrt), F(ceil), F_opt(cos), F(cosh), F(erf), F(erfc), @@ -268,7 +269,7 @@ env_t *global_env(bool source_mapping) {"INF", "(Num32_t)(INFINITY)", "Num32"}, {"TAU", "(Num32_t)(2.f*M_PI)", "Num32"}, {"mix", "Num32$mix", "func(amount,x,y:Num32 -> Num32)"}, - {"parse", "Num32$parse", "func(text:Text -> Num32?)"}, + {"parse", "Num32$parse", "func(text:Text, remainder:&Text? = none -> Num32?)"}, {"abs", "fabsf", "func(n:Num32 -> Num32)"}, {"modulo", "Num32$mod", "func(x,y:Num32 -> Num32)"}, {"modulo1", "Num32$mod1", "func(x,y:Num32 -> Num32)"}, @@ -345,7 +346,7 @@ env_t *global_env(bool source_mapping) {"bytes", "Text$utf8_bytes", "func(text:Text -> [Byte])"}, {"caseless_equals", "Text$equal_ignoring_case", "func(a,b:Text, language='C' -> Bool)"}, {"codepoint_names", "Text$codepoint_names", "func(text:Text -> [Text])"}, - {"ends_with", "Text$ends_with", "func(text,suffix:Text -> Bool)"}, + {"ends_with", "Text$ends_with", "func(text,suffix:Text, remainder:&Text? = none -> Bool)"}, {"from", "Text$from", "func(text:Text, first:Int -> Text)"}, {"from_bytes", "Text$from_bytes", "func(bytes:[Byte] -> Text?)"}, {"from_c_string", "Text$from_str", "func(str:CString -> Text?)"}, @@ -368,7 +369,7 @@ env_t *global_env(bool source_mapping) {"slice", "Text$slice", "func(text:Text, from=1, to=-1 -> Text)"}, {"split", "Text$split", "func(text:Text, delimiter='' -> [Text])"}, {"split_any", "Text$split_any", "func(text:Text, delimiters=' \\t\\r\\n' -> [Text])"}, - {"starts_with", "Text$starts_with", "func(text,prefix:Text -> Bool)"}, + {"starts_with", "Text$starts_with", "func(text,prefix:Text, remainder:&Text? = none -> Bool)"}, {"title", "Text$title", "func(text:Text, language='C' -> Text)"}, {"to", "Text$to", "func(text:Text, last:Int -> Text)"}, {"translate", "Text$translate", "func(text:Text, translations:{Text=Text} -> Text)"}, -- cgit v1.2.3