Created
December 31, 2010 16:07
-
-
Save colomon/761112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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