Skip to content

Instantly share code, notes, and snippets.

@colomon
Created December 31, 2010 16:07
Show Gist options
  • Save colomon/761112 to your computer and use it in GitHub Desktop.
Save colomon/761112 to your computer and use it in GitHub Desktop.
my %constraint =
# Prompter Add to What to print on Use this to check that Conversion
# type prompt invalid input input is valid function
# ======== ====== ================ ====================== ==========
::Int => [': ', 'a valid integer', /^ \h* <integer> \h* $/, *.Int ],
::Num => [': ', 'a valid number', /^ \h* <number> \h* $/, +* ],
::Bool => ['? ', '"yes" or "no"', /^ \h* <yesno> \h* $/, {?/<yes>/} ],
SemiBool => ['? ', '"yes" or "no"', /^ \h* \S+ \h* $/, {?/<yes>/} ],
CapSemiBool => ['? ', '"Yes" for yes', /^ \h* <Yes> \h* $/, {?/<yes>/} ],
CapFullBool => ['? ', '"Yes" or "No"', /^ \h* <YesNo> \h* $/, {?/<yes>/} ],
Any => [': ', 'anything', / <null> /, { $^self } ];
my ($punct, $description, $match, $extractor)
= %constraint{$type} // %constraint<Any>;
# does not work in current Rakudo: the entire Array in %constraint{$type} is assigned to $punct,
# while the remainder of $description, etc get Any().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment