Skip to content

Instantly share code, notes, and snippets.

@yeahnoob
Forked from colomon/gist:c2d2c1940b92d8d9df01
Last active August 29, 2015 14:06
Show Gist options
  • Save yeahnoob/355da51f635e28699584 to your computer and use it in GitHub Desktop.
Save yeahnoob/355da51f635e28699584 to your computer and use it in GitHub Desktop.
grammar WordPairs {
rule word-pair { <key=word> <value=word> }
token word { \S+ }
rule TOP { <word-pair>* }
}
my %dict;
class WordPairsActions {
method word-pair($/) { %dict{~$<key>}.push(~$<value>) }
}
my $match = WordPairs.parse(slurp, :actions(WordPairsActions));
say ?$match;
say "The pairs count of the key word \"her\" in wordpairs.txt is {%dict{"her"}.elems}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment