Advertisement
Guest User

Untitled

a guest
Nov 18th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.17 KB | None | 0 0
  1. use v6; use Term::ANSIColor;
  2. ###################################################################
  3. grammar Record {
  4.     token TOP       { <record> }
  5.     token record        { <stardate> \t <topic> \t <remarks> }
  6.     token stardate      { <year> \- <month> \- <day> <zulutime> }
  7.     token year      { \d**4 }
  8.     token month     { \d**2 }
  9.     token day       { \d**2 }
  10.     token zulutime      { T \d**2 \: \d**2 \: \d**2 Z }
  11.     token topic     { \T* }
  12.     token remarks       { [ <item> || \T ]*  }
  13.     token item      { <key> \s <value> } # Key:_Value,
  14.     token key       { \w+ \: }
  15.     token value     { \w+ \, }
  16. }
  17. ####################################################################
  18. my $text = Q {2011-10-26T05:20:15Z  TESTING Remarks here including a few KEY: someValue, KEY: anotherValue, and more text.};
  19. my $match = Record.parse($text);
  20. ####################################################################
  21. run("clear");
  22. say "Input: "~$text.perl;  
  23. if ($match ) {say "Parse Grammar Test: TRUE";} else {say "Parse Grammar Test: FALSE";}
  24. say "Match Obj: "~$match.perl;
  25. say "Stardate: "~$match<record><stardate>;
  26. say "Topic: "~$match<record><topic>;
  27. say "Remarks: "~$match<record><remarks>;
  28. say "Items: "~$match<record><remarks><item>.perl; #NOT WORKING...?
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement