Skip to content

Instantly share code, notes, and snippets.

@sirrobert
Created December 12, 2012 16:33
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 sirrobert/4269302 to your computer and use it in GitHub Desktop.
Save sirrobert/4269302 to your computer and use it in GitHub Desktop.
Parsing a file with newlines
my $str = "
TITLE: My Title
This is an example of some paragraph text. One of the
key characteristics is that it can span multiple lines.
This is another paragraph.
";
grammar MyGrammar {
token TOP { ^ <element>+ $ }
token element { [<title> | <paragraph>] "\n\n" }
token title { \s* 'TITLE:' \s* \N* }
token paragraph { \N* }
}
class MyActions {
method TOP ($/) {}
method element ($/) {}
method title ($/) { say "$/" }
method paragraph ($/) { say "$/" }
}
my $result = MyGrammar.parse: $str;
say $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment