Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6; use Term::ANSIColor;
- ###################################################################
- grammar Record {
- token TOP { <record> }
- token record { <stardate> \t <topic> \t <remarks> }
- token stardate { <year> \- <month> \- <day> <zulutime> }
- token year { \d**4 }
- token month { \d**2 }
- token day { \d**2 }
- token zulutime { T \d**2 \: \d**2 \: \d**2 Z }
- token topic { \T* }
- token remarks { [ <item> || \T ]* }
- token item { <key> \s <value> } # Key:_Value,
- token key { \w+ \: }
- token value { \w+ \, }
- }
- ####################################################################
- my $text = Q {2011-10-26T05:20:15Z TESTING Remarks here including a few KEY: someValue, KEY: anotherValue, and more text.};
- my $match = Record.parse($text);
- ####################################################################
- run("clear");
- say "Input: "~$text.perl;
- if ($match ) {say "Parse Grammar Test: TRUE";} else {say "Parse Grammar Test: FALSE";}
- say "Match Obj: "~$match.perl;
- say "Stardate: "~$match<record><stardate>;
- say "Topic: "~$match<record><topic>;
- say "Remarks: "~$match<record><remarks>;
- say "Items: "~$match<record><remarks><item>.perl; #NOT WORKING...?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement