Created
December 1, 2017 11:37
-
-
Save FCO/53427981f39d328599a2b86da46daaad 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 Grammar::Tracer; | |
BEGIN $*LANG.refine_slang: 'MAIN', | |
role P6X { | |
#grammar XML { | |
token p6x-word { | |
\w+ | |
} | |
token p6x-attr { | |
<p6x-word> '=' [ | |
| '"' ~ '"' $<p6x-value>=.*? | |
| "'" ~ "'" $<p6x-value>=.*? | |
| $<p6x-value>=<.p6x-word> | |
] | |
} | |
token p6x-inner-tag { | |
$<p6x-name>=<.p6x-word> | |
<p6x-attr>* %% <.ws> | |
} | |
token p6x-closing-tag($name) { | |
'</' ~ '>' $name | |
} | |
token p6x-opening-tag { | |
'<' ~ '>' <p6x-inner-tag> | |
} | |
token p6x-unique-tag { | |
'<' ~ '/>' <p6x-inner-tag> | |
} | |
token p6x-open-close-tag { | |
:my $name; | |
[<p6x-opening-tag> {$name = $<p6x-opening-tag><p6x-inner-tag><p6x-name>}] ~ <p6x-closing-tag($name)> | |
$<p6x-inner> = [ | |
|| <p6x-xml>+ $<p6x-post-data>=.*? | |
|| $<p6x-pre-data>=.+? <p6x-xml>+ $<p6x-post-data>=.*? | |
|| .*? | |
] | |
} | |
token p6x-tag { | |
|| <p6x-unique-tag> | |
|| <p6x-open-close-tag> | |
} | |
token p6x-xml { | |
<p6x-tag> | |
} | |
token statement_control:sym<p6x> { | |
<p6x-xml> | |
} | |
#token TOP { <p6x-xml> } | |
#say XML.parse: "<head>bla<br /><form>bla: <input /></form></head>" | |
}, | |
role P6XActions { | |
method statement_control:sym<p6x> (Mu $/) { | |
say $/; | |
nextsame | |
} | |
} | |
<head> | |
<body> | |
bla<br /> | |
<form> | |
bla: <input /> | |
</form> | |
</body> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment