diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-12-14 18:39:56 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-12-14 18:39:56 -0800 |
| commit | 9617baf699aeff816fae50841e11123ebd9c9366 (patch) | |
| tree | 504da046e6c109529b66801b5d08d6d1bddc7689 | |
| parent | c9daa5f29f1b23e7ce3180b77029b7f61313df20 (diff) | |
Updated grammars
| -rw-r--r-- | grammars/bpeg.bp | 9 | ||||
| -rw-r--r-- | grammars/builtins.bp | 9 | ||||
| -rw-r--r-- | grammars/html.bp | 18 |
3 files changed, 17 insertions, 19 deletions
diff --git a/grammars/bpeg.bp b/grammars/bpeg.bp index 288ceee..88d986a 100644 --- a/grammars/bpeg.bp +++ b/grammars/bpeg.bp @@ -7,7 +7,7 @@ Def: @name=id _ `: __ ( / @!={...>(`;/id_`:/$) => "Invalid definition: @0"}) # This is used for command line arguments: -String-pattern: *(`\ (escape-sequence / pat [`;]) / .) +String-pattern: ... % (`\ (escape-sequence / pat [`;])) pat: simple-pat !(__("!="/"==")) / suffixed-pat simple-pat: Upto-and / Dot / String / Char-range / Char / Escape-range / Escape / No @@ -40,9 +40,10 @@ escape-sequence: ( ) No: `! (_@pat / @!={=>"Expected a pattern after the exclamation mark"}) Nodent: `| -Upto-and: 2-3`. [_@simple-pat] +Upto-and: 2-3`. [_@first=simple-pat] [__`%__@second=simple-pat] Repeat: ( - @min=int _ `- _ @max=int + @min='' `* @max='' + / @min=int _ `- _ @max=int / @min=int _ `+ @max='' / @min=@max=int ) __ @repeat-pat=pat [__`%__@sep=pat] @@ -72,7 +73,7 @@ $: !. id: "^^" / "^" / "__" / "_" / "$$" / "$" / (`a-z/`A-Z) *(`a-z/`A-Z/`0-9/`-) line-comment: `# .. $ -block-comment: "#(" *(block-comment / !")#" .) ")#" +block-comment: "#("..")#" % block-comment # Note: comments are undefined by default in regular BPEG comment: block-comment / line-comment diff --git a/grammars/builtins.bp b/grammars/builtins.bp index 7de936f..ec541bf 100644 --- a/grammars/builtins.bp +++ b/grammars/builtins.bp @@ -49,10 +49,11 @@ utf8-codepoint: ( ) crlf: \r\n cr: \r -anglebraces: `< *(anglebraces / $. != `>) `> -brackets: `[ *(brackets / $. != `]) `] -braces: `{ *(braces / $. != `}) `} -parens: `( *(parens / $. != `)) `) +anglebraces: `<..`> % (anglebraces/string) +brackets: `[..`] % (brackets/string) +braces: `{..`} % (braces/string) +parens: `(..`} % (parens/string) +string: `"..`" % (`\.) / `'..`' % (`\.) id: !<(`a-z/`A-Z/`_/`0-9) (`a-z/`A-Z/`_) *(`a-z/`A-Z/`_/`0-9) id-char: `a-z/`A-Z/`_/`0-9 word: !<(`a-z/`A-Z/`_/`0-9) +(`a-z/`A-Z) !>(`0-9/`_) diff --git a/grammars/html.bp b/grammars/html.bp index cea19c1..1f6553c 100644 --- a/grammars/html.bp +++ b/grammars/html.bp @@ -3,24 +3,20 @@ 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) +html-element: void-element / raw-element / template-element / normal-element -void-element: `< @tag=(id==match-tag) __attributes__ [`/] __ `> +void-element: `< ("area"/"base"/"br"/"col"/"embed"/"hr"/"img"/"input"/"link"/"meta"/"param"/"source"/"track"/"wbr") __attributes__ [`/] __ `> -template-element: `< @tag=(id==match-tag) __`> __ >match-body @body=*(!`<$. / comment / html-element / !("</"tag__`>)$.) ("</"tag__`>) +template-element: "<template>"...("</template>") % (comment / html-element) -raw-element: `< @tag=(id==match-tag) __attributes__ `> >match-body @body=.. ("</"tag__`>) +raw-element: `< @tag=("script"/"style"/"textarea"/"title") __attributes__ `>...("</"tag__`>) -normal-element: `< @tag=(id==match-tag) __attributes__ `> >match-body @body=*(!`<$. / comment / html-element / !("</"tag__`>)$.) "</"tag__`> +normal-element: `< @tag=( + "area"/"base"/"br"/"col"/"embed"/"hr"/"img"/"input"/"link"/"meta"/"param"/"source"/"track"/"wbr") + __attributes__ `>...("</"tag`>) % (comment / html-element) comment: "<!--" ..."-->" attributes: *attribute%__ attribute: (+id%`:)__`=__ (id / `" ..`" / `' ..`') attribute: (+id%`:)__`=__ (id / `" ..`" / `' ..`') -match-tag: id -match-body: '' |
