Skip to content

Instantly share code, notes, and snippets.

@ShimmerFairy
Created August 29, 2010 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShimmerFairy/556545 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/556545 to your computer and use it in GitHub Desktop.
use v6;
grammar Markov {
token TOP {
[<comment>|<command>]+
}
token comment {
^^ '#' \N* \n
}
token command {
^^ $<item>=[\S+] <ws> '->' <ws> $<stop>=['.'?] $<replacement>=[\N+] \n
}
}
my $test = Q {# This rules file is extracted from Wikipedia:
# http://en.wikipedia.org/wiki/Markov_Algorithm
A -> apple
B -> bag
S -> shop
T -> the
the shop -> my brother
a never used -> .terminating rule
};
my $match = Markov.parse($test);
say $match.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment