Last active
July 24, 2023 21:08
-
-
Save librasteve/c3164d3744950c4370c1560b52bdae34 to your computer and use it in GitHub Desktop.
measure-regex.raku
This file contains 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
use Physics::Measure :ALL; | |
$Physics::Measure::number-comma = ''; | |
my @lines = q:to/END/; | |
say &fs('car in USA highway'); | |
# The average speed of cars on US highways is approximately 65 mph. | |
say &fs('rocket leaving Earth'); | |
#The average speed of a rocket leaving Earth is approximately 7.8 km/s. | |
say &fs('rocket leaving Earth in miles per hour'); | |
# The average speed of a rocket leaving Earth is approximately 25,000 mph. | |
END | |
for @lines.split("\n").grep( / \# / ) -> $line { | |
$line ~~ / 'is approximately ' (.*?) '.' $/; | |
say ♎️"$0"; | |
} | |
say '--'; | |
my regex measure { | |
.+ #grab chars | |
<?{ ♎️"$/" ~~ Measure }> #assert coerces via '♎️' to Measure | |
} | |
for @lines.split("\n").grep( / \# / ) -> $line is copy { | |
$line .= chop; | |
$line ~~ / 'is approximately ' <measure> $/; | |
say ♎️"$/<measure>"; | |
} |
Author
librasteve
commented
Jul 24, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment