bp/grammars/html.bpeg

28 lines
1.1 KiB
Plaintext

# HTML grammar
HTML = __ ?(doctype __) *html-element%__ __;
doctype = "<!DOCTYPE" &`>;
html-element = (
>(`<("area"/"base"/"br"/"col"/"embed"/"hr"/"img"/"input"/"link"/"meta"/"param"/"source"/"track"/"wbr")) void-element
/ >(`<("script"/"style"/"textarea"/"title")) raw-element
/ >(`<("template")) template-element
/ normal-element);
void-element = `< @[tag](id==match-tag) __attributes__ `/? __ `>;
template-element = `< @[tag](id==match-tag) __`> __ >match-body @[body]0+(!`<$. / comment / html-element / !("</"tag__`>)$.) ("</"tag__`>);
raw-element = `< @[tag](id==match-tag) __attributes__ `> >match-body @[body].. ("</"tag__`>);
normal-element = `< @[tag](id==match-tag) __attributes__ `> >match-body @[body]*(!`<$. / comment / html-element / !("</"tag__`>)$.) "</"tag__`>;
comment = "<!--" &&"-->";
attributes = *(!(attribute==match-attribute))%__ __(attribute==match-attribute)__ *attribute%__;
attribute = (+id%`:)__`=__ (id / `" &`" / `' &`');
attribute = (+id%`:)__`=__ (id / `" .. `" / `' .. `');
match-attribute = attribute;
match-tag = id;
match-body = (/);