diff options
Diffstat (limited to 'stdlib/source/library/lux/data/text/regex.lux')
-rw-r--r-- | stdlib/source/library/lux/data/text/regex.lux | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/stdlib/source/library/lux/data/text/regex.lux b/stdlib/source/library/lux/data/text/regex.lux index 34ce70739..6648375ba 100644 --- a/stdlib/source/library/lux/data/text/regex.lux +++ b/stdlib/source/library/lux/data/text/regex.lux @@ -26,11 +26,11 @@ ["[0]" // (.only) ["%" \\format (.only format)]]) -(def: regex_char^ +(def regex_char^ (Parser Text) (<text>.none_of "\.|&()[]{}")) -(def: escaped_char^ +(def escaped_char^ (Parser Text) (do <>.monad [? (<>.parses? (<text>.this "\"))] @@ -38,31 +38,31 @@ <text>.any regex_char^))) -(def: (refine^ refinement^ base^) +(def (refine^ refinement^ base^) (All (_ a) (-> (Parser a) (Parser Text) (Parser Text))) (do <>.monad [output base^ _ (<text>.local output refinement^)] (in output))) -(def: word^ +(def word^ (Parser Text) (<>.either <text>.alpha_num (<text>.one_of "_"))) -(def: (copy reference) +(def (copy reference) (-> Text (Parser Text)) (<>.after (<text>.this reference) (<>#in reference))) -(def: together^ +(def together^ (-> (Parser (List Text)) (Parser Text)) (at <>.monad each //.together)) -(def: symbol_char^ +(def symbol_char^ (Parser Text) (<text>.none_of (format "[]{}()s.<>" //.double_quote))) -(def: symbol_part^ +(def symbol_part^ (Parser Text) (do <>.monad [head (refine^ (<text>.not <text>.decimal) @@ -70,7 +70,7 @@ tail (<text>.some symbol_char^)] (in (format head tail)))) -(def: (symbol^ current_module) +(def (symbol^ current_module) (-> Text (Parser Symbol)) (all <>.either (<>.and (<>#in current_module) (<>.after (<text>.this "..") symbol_part^)) @@ -78,13 +78,13 @@ (<>.and (<>#in .prelude) (<>.after (<text>.this ".") symbol_part^)) (<>.and (<>#in "") symbol_part^))) -(def: (re_var^ current_module) +(def (re_var^ current_module) (-> Text (Parser Code)) (do <>.monad [symbol (<text>.enclosed ["\@<" ">"] (symbol^ current_module))] (in (` (is ((~! <text>.Parser) Text) (~ (code.symbol symbol))))))) -(def: re_range^ +(def re_range^ (Parser Code) (do [! <>.monad] [from (|> regex_char^ (at ! each (|>> (//.char 0) maybe.trusted))) @@ -92,19 +92,19 @@ to (|> regex_char^ (at ! each (|>> (//.char 0) maybe.trusted)))] (in (` ((~! <text>.range) (~ (code.nat from)) (~ (code.nat to))))))) -(def: re_char^ +(def re_char^ (Parser Code) (do <>.monad [char escaped_char^] (in (` ((~! ..copy) (~ (code.text char))))))) -(def: re_options^ +(def re_options^ (Parser Code) (do <>.monad [options (<text>.many escaped_char^)] (in (` ((~! <text>.one_of) (~ (code.text options))))))) -(def: re_user_class^' +(def re_user_class^' (Parser Code) (do <>.monad [negate? (<>.maybe (<text>.this "^")) @@ -115,7 +115,7 @@ {.#Some _} (` ((~! <text>.not) (all ((~! <>.either)) (~+ parts)))) {.#None} (` (all ((~! <>.either)) (~+ parts))))))) -(def: re_user_class^ +(def re_user_class^ (Parser Code) (do <>.monad [init ..re_user_class^' @@ -127,34 +127,34 @@ init rest)))) -(def: blank^ +(def blank^ (Parser Text) (<text>.one_of (format " " //.tab))) -(def: ascii^ +(def ascii^ (Parser Text) (<text>.range (hex "0") (hex "7F"))) -(def: control^ +(def control^ (Parser Text) (<>.either (<text>.range (hex "0") (hex "1F")) (<text>.one_of (//.of_char (hex "7F"))))) -(def: punct^ +(def punct^ (Parser Text) (<text>.one_of (format "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" //.double_quote))) -(def: graph^ +(def graph^ (Parser Text) (<>.either punct^ <text>.alpha_num)) -(def: print^ +(def print^ (Parser Text) (<>.either graph^ (<text>.one_of (//.of_char (hex "20"))))) -(def: re_system_class^ +(def re_system_class^ (Parser Code) (do <>.monad [] @@ -183,17 +183,17 @@ (<>.after (<text>.this "\p{Print}") (in (` (~! print^)))) ))) -(def: re_class^ +(def re_class^ (Parser Code) (<>.either re_system_class^ (<text>.enclosed ["[" "]"] re_user_class^))) -(def: number^ +(def number^ (Parser Nat) (|> (<text>.many <text>.decimal) (<>.codec n.decimal))) -(def: re_back_reference^ +(def re_back_reference^ (Parser Code) (<>.either (do <>.monad [_ (<text>.this "\") @@ -205,7 +205,7 @@ _ (<text>.this ">")] (in (` ((~! ..copy) (~ (code.symbol ["" captured_symbol])))))))) -(def: (re_simple^ current_module) +(def (re_simple^ current_module) (-> Text (Parser Code)) (all <>.either re_class^ @@ -214,7 +214,7 @@ re_char^ )) -(def: (re_simple_quantified^ current_module) +(def (re_simple_quantified^ current_module) (-> Text (Parser Code)) (do <>.monad [base (re_simple^ current_module) @@ -237,7 +237,7 @@ "Input" (format (%.nat from) "," (%.nat to)) "Should be" (format (%.nat to) "," (%.nat from)))) -(def: (re_counted_quantified^ current_module) +(def (re_counted_quantified^ current_module) (-> Text (Parser Code)) (do [! <>.monad] [base (re_simple^ current_module)] @@ -261,12 +261,12 @@ [limit number^] (in (` ((~! together^) ((~! <>.exactly) (~ (code.nat limit)) (~ base)))))))))) -(def: (re_quantified^ current_module) +(def (re_quantified^ current_module) (-> Text (Parser Code)) (<>.either (re_simple_quantified^ current_module) (re_counted_quantified^ current_module))) -(def: (re_complex^ current_module) +(def (re_complex^ current_module) (-> Text (Parser Code)) (all <>.either (re_quantified^ current_module) @@ -277,7 +277,7 @@ {#Non_Capturing} {#Capturing [(Maybe Text) Nat]})) -(def: (re_sequential^ capturing? re_scoped^ current_module) +(def (re_sequential^ capturing? re_scoped^ current_module) (-> Bit (-> Text (Parser [Re_Group Code])) Text @@ -329,11 +329,11 @@ ((~ (' in)) [(~ g!total) (~+ (list.reversed names))])))]) )) -(def: (unflatten^ lexer) +(def (unflatten^ lexer) (-> (Parser Text) (Parser [Text Any])) (<>.and lexer (at <>.monad in []))) -(def: (|||^ left right) +(def (|||^ left right) (All (_ l r) (-> (Parser [Text l]) (Parser [Text r]) (Parser [Text (Or l r)]))) (function (_ input) (case (left input) @@ -348,7 +348,7 @@ {try.#Failure error} {try.#Failure error})))) -(def: (|||_^ left right) +(def (|||_^ left right) (All (_ l r) (-> (Parser [Text l]) (Parser [Text r]) (Parser Text))) (function (_ input) (case (left input) @@ -363,13 +363,13 @@ {try.#Failure error} {try.#Failure error})))) -(def: (prep_alternative [num_captures alt]) +(def (prep_alternative [num_captures alt]) (-> [Nat Code] Code) (if (n.> 0 num_captures) alt (` ((~! unflatten^) (~ alt))))) -(def: (re_alternative^ capturing? re_scoped^ current_module) +(def (re_alternative^ capturing? re_scoped^ current_module) (-> Bit (-> Text (Parser [Re_Group Code])) Text @@ -387,7 +387,7 @@ (~ (prep_alternative head)) (~+ (list#each prep_alternative tail))))])))) -(def: (re_scoped^ current_module) +(def (re_scoped^ current_module) (-> Text (Parser [Re_Group Code])) (all <>.either (do <>.monad @@ -411,11 +411,11 @@ _ (<text>.this ")")] (in [{#Capturing [{.#None} num_captures]} pattern])))) -(def: (regex^ current_module) +(def (regex^ current_module) (-> Text (Parser Code)) (at <>.monad each product.right (re_alternative^ #1 re_scoped^ current_module))) -(def: .public regex +(def .public regex (syntax (_ [pattern <code>.text]) (do meta.monad [current_module meta.current_module_name] @@ -428,7 +428,7 @@ {try.#Success regex} (in (list regex)))))) -(def: .public pattern +(def .public pattern (syntax (_ [[pattern bindings] (<code>.form (<>.and <code>.text (<>.maybe <code>.any))) body <code>.any branches (<>.many <code>.any)]) |