Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Last active August 29, 2015 14:00
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 FROGGS/3b7cebc3301e050a9b9a to your computer and use it in GitHub Desktop.
Save FROGGS/3b7cebc3301e050a9b9a to your computer and use it in GitHub Desktop.
#!/opt/bin/perl6
my $file = q:to/END/;
=data ab cd ef gh ij kl
# ab cd ef gh ij
2: 6 8 0 15 6 1
3: 6 7 0 10 3 2
4: 8 8 2 13 5 8
5: 11 15 1 13 8 5
7: 8 8 2 15 2 1
8: 3 8 1 8 7 4
#~ 9: 6 8 2 15 10 5
#~ 10: 7 8 1 12 10 4
#~ 11: 7 8 1 10 8 4
#~ 12: 12 15 2 13 7 3
#~ 14: 2 7 1 7 6 1
#~ 15: 7 8 2 14 5 3
#~ 16: 6 8 2 15 9 4
#~ 17: 4 8 1 15 7 8
#~ 18: 8 8 2 15 8 3
#~ 19: 13 15 0 0 5 2
#~ 21: 1 8 1 12 3 5
#~ 22: 7 8 1 11 3 1
#~ 23: 7 8 1 13 8 2
#~ 24: 6 8 0 15 8 3
#~ 25: 5 8 0 13 4 4
#~ 26: 14 15 2 13 6 4
=data ab cd ef gh ij kl mn
28: 0 9 2 15 6 4 5
29: 8 8 1 13 10 2 4
30: 5 6 0 11 7 3 3
31: 7 8 0 15 2 3 1
END
grammar GRAMMAR {
token TOP { [ <header> | <.comment> ]+ };
token header { '=data ' <cs>+ % [\h+] \n [ <dline> | <.comment> ]* };
token comment { '#' \N+ \n };
token dline { \d+ ': ' <data>+ % [\h+] \n };
token data { \d+ };
token cs { \w+ };
};
my $r = GRAMMAR.parse( $file );
say $r<header>[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment