Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env raku
- use v6.d;
- grammar Timestamp {
- token TOP { <year><month><day>T<hours><minutes> }
- token year { \d**4 }
- token month { \d**2 }
- token day { \d**2 }
- token hours { \d**2 }
- token minutes { \d**2 }
- }
- grammar Filename {
- token TOP { <name>'-'<timestamp>'.'<extension> }
- token name { <[a..z]>+ }
- token extension { <[a..z]>**3 }
- method timestamp { Timestamp.subparse(self.orig, :pos(self.to)) }
- }
- my \x = Filename.parse('foo-20240102T1234.bar');
- say "Name: {x<name>}";
- say "Extension: {x<extension>}";
- say
- "Timestamp:"
- ~ " {x<timestamp><day>}.{x<timestamp><month>}.{x<timestamp><year>}"
- ~ " {x<timestamp><hours>}:{x<timestamp><minutes>}";
- # Prints:
- # Name: foo
- # Extension: bar
- # Timestamp: 02.01.2024 12:34
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement