Guest User

Untitled

a guest
Jul 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. my %constraint =
  2. # Prompter Add to What to print on Use this to check that Conversion
  3. # type prompt invalid input input is valid function
  4. # ======== ====== ================ ====================== ==========
  5. ::Int => [': ', 'a valid integer', /^ \h* <integer> \h* $/, *.Int ],
  6. ::Num => [': ', 'a valid number', /^ \h* <number> \h* $/, +* ],
  7. ::Bool => ['? ', '"yes" or "no"', /^ \h* <yesno> \h* $/, {?/<yes>/} ],
  8. SemiBool => ['? ', '"yes" or "no"', /^ \h* \S+ \h* $/, {?/<yes>/} ],
  9. CapSemiBool => ['? ', '"Yes" for yes', /^ \h* <Yes> \h* $/, {?/<yes>/} ],
  10. CapFullBool => ['? ', '"Yes" or "No"', /^ \h* <YesNo> \h* $/, {?/<yes>/} ],
  11. Any => [': ', 'anything', / <null> /, { $^self } ];
  12.  
  13.  
  14. my ($punct, $description, $match, $extractor)
  15. = %constraint{$type} // %constraint<Any>;
  16.  
  17. # does not work in current Rakudo: the entire Array in %constraint{$type} is assigned to $punct,
  18. # while the remainder of $description, etc get Any().
Add Comment
Please, Sign In to add comment