Created
December 12, 2012 16:33
-
-
Save sirrobert/4269302 to your computer and use it in GitHub Desktop.
Parsing a file with newlines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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