Created
December 2, 2015 20:30
-
-
Save zoffixznet/4b066b9928a6a89e8dae to your computer and use it in GitHub Desktop.
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
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