Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2016 06:45
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 anonymous/4d0c6c1d9f16b4d34307c6dccae3800a to your computer and use it in GitHub Desktop.
Save anonymous/4d0c6c1d9f16b4d34307c6dccae3800a to your computer and use it in GitHub Desktop.
use v6;
use Grammar::Tracer;
grammar ML {
rule TOP { <tag> }
token identifier { \w <[\w\d]>* }
token quote { <!after \\> '"' }
token quoted { <.quote> ~ <.quote> <.-quote>* }
token tag {
[<btag> ~ <etag($<btag><name>)>
<-lt>*
]
| <sctag>
}
token sctag { <.lt> \s* <name=.identifier> [\s+ [<attribute>*% \s+]]? '/' <.gt> }
token btag { <.lt> \s* <name=.identifier> [\s+ [<attribute>*% \s+]]? <.gt> }
token etag($name) { <.lt> '/' \s* $name \s* <.gt> }
token lt { <!after \\> '<' }
token gt { <!after \\> '>' }
token attribute { <identifier> [\s* '=' \s* <quoted>]? }
regex child { <-lt>* | <tag> }
}
sub MAIN(){
ML.parse('<input type="hidden" name="secret"></input>').say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment