Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created December 2, 2015 20:30
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 zoffixznet/4b066b9928a6a89e8dae to your computer and use it in GitHub Desktop.
Save zoffixznet/4b066b9928a6a89e8dae to your computer and use it in GitHub Desktop.
use v6;
my $css = q:to/END/;
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
* { font-size: 1em; }
.Constant { color: #0000c0; text-decoration: underline; }
.Comment { color: #c00000; font-weight: bold; }
.Special { color: #c000c0; font-weight: bold; }
.Identifier { color: #804000; text-decoration: underline; }
.Statement { color: #008080; font-weight: bold; }
.PreProc { color: #c000c0; text-decoration: underline; }
.Type { color: #008000; text-decoration: underline; }
-->
END
grammar KeyValuePairs {
token TOP {
[<pair> \n+]*
}
token ws { \h* }
rule pair {
\.<c=.c> '{' <rules=.rules> '}'
}
token c { \w+ }
token rules { <-[}]>+ }
}
class KeyValuePairsActions {
method c ($/) { $/.make: ~$/ }
method rules ($/) { $/.make: ~$/ }
method pair ($/) { $/.make: $<c>.made => $<rules>.made }
method TOP ($/) { $/.make: $<pair>».made }
}
my $res = KeyValuePairs.parse($css, :actions(KeyValuePairsActions)).made;
for @$res -> $p {
say $p
# say "Key: $p.c()\tValue: $p.rules()";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment