Advertisement
Guest User

Untitled

a guest
Jan 1st, 2024
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.70 KB | None | 0 0
  1. #! /usr/bin/env raku
  2.  
  3. use v6.d;
  4.  
  5. grammar Timestamp {
  6.     rule TOP { <year><month><day>T<hours><minutes> }
  7.     token year { \d**4 }
  8.     token month { \d**2 }
  9.     token day { \d**2 }
  10.     token hours { \d**2 }
  11.     token minutes { \d**2 }
  12. }
  13.  
  14. grammar Filename {
  15. # This line fails with:
  16. # Cannot look up attributes in a Nil type object. Did you forget a '.new'?
  17. #   in regex TOP at ./test-nesting-grammar.raku line 16
  18. #   in block <unit> at ./test-nesting-grammar.raku line 23
  19.     rule TOP { <name>'-'<timestamp>'.'<extension> }
  20.     token name { <[a..z]>+ }
  21.     token extension { <[a..z]>**3 }
  22. }
  23.  
  24. Filename.^add_method("timestamp", -> *@_, *%_ { Timestamp.parse(@_[*-1].orig) });
  25.  
  26. Filename.parse('foo-20240102T1234.bar').say;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement