diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-09-12 18:20:13 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-09-12 18:20:13 -0700 |
| commit | c18eb4c9968289c4808d70f7124c0b6bed5eb022 (patch) | |
| tree | 97fdbee687e2e83f83403161365b90c99c102ee6 /grammars | |
| parent | c0125378b9ec96149aed3107bff719cd8a01b16d (diff) | |
Added backrefs
Diffstat (limited to 'grammars')
| -rw-r--r-- | grammars/builtins.bpeg | 41 | ||||
| -rw-r--r-- | grammars/html.bpeg | 18 |
2 files changed, 59 insertions, 0 deletions
diff --git a/grammars/builtins.bpeg b/grammars/builtins.bpeg new file mode 100644 index 0000000..0de9ae3 --- /dev/null +++ b/grammars/builtins.bpeg @@ -0,0 +1,41 @@ +# Meta-rules for acting on everything +pattern = !(/); # Not defined by default +replacement = {!(/)=>}; # Not defined by default +replace-all = *&&@replacement &&$$; +find-all = *(matching-line / {&&(\n/$$)=>}); +only-matches = *{&&@pattern=>'@1\n'}; +matching-line = +&@pattern *. $ ?\n; + +# Helper definitions (commonly used) +crlf = \r\n; +cr = \r; r = \r; +anglebraces = `< *(anglebraces / ~~`>) `>; +brackets = `[ *(brackets / ~~`]) `]; +braces = `{ *(braces / ~~`}) `}; +parens = `( *(parens / ~~`)) `); +id = (`a-z/`A-Z/`_) *(`a-z/`A-Z/`_/`0-9); +HEX = `0-9/`A-F; +Hex = `0-9/`a-f/`A-F; +hex = `0-9/`a-f; +number = +`0-9 ?(`. *`0-9) / `. +`0-9; +int = +`0-9; +digit = `0-9; +Abc = `a-z/`A-Z; +ABC = `A-Z; +abc = `a-z; +esc = \e; e = \e; +tab = \t; t = \t; +nl = \n; lf = \n; n = \n; +c-block-comment = '/*' &&'*/'; +c-line-comment = '//' &$; +c-comment = c-line-comment / c-block-comment; +hash-comment = `# &$; +comment = !(/); # No default definition, can be overridden +WS = ` /\t/\n/\r/comment; +ws = ` /\t; +$$ = !$.; +$ = !.; +^^ = !<$.; +^ = !<.; +__ = *(` /\t/\n/\r/comment); +_ = *(` /\t); diff --git a/grammars/html.bpeg b/grammars/html.bpeg new file mode 100644 index 0000000..f6812bd --- /dev/null +++ b/grammars/html.bpeg @@ -0,0 +1,18 @@ +# HTML grammar +HTML = __ ?(doctype __) *html-element%__ __; + +doctype = "<!DOCTYPE" &`>; + +html-element = void-element / template-element / raw-text-element / normal-element; + +void-element = `< ("area"/"base"/"br"/"col"/"embed"/"hr"/"img"/"input"/"link"/"meta"/"param"/"source"/"track"/"wbr") *(__attribute) __ ?`/ __ `>; + +template-element = "<template" __`> __ *(~~`< / comment / html-element / ~~("</template"__`>)) ("</template"__`>); + +raw-text-element = `<@[tag]("script"/"style"/"textarea"/"title") *(__attribute) __ `> &("</"tag__`>); + +normal-element = !raw-text-element `<@[tag]id *(__attribute) __ `> *(~~`< / comment / html-element / ~~("</"tag__`>)) "</"tag__`>; + +comment = "<!--" &&"-->"; + +attribute = +id%`:__`=__(id / `" &`" / `' &`'); |
