Updated grammars

This commit is contained in:
Bruce Hill 2020-12-14 18:39:56 -08:00
parent c9daa5f29f
commit 9617baf699
3 changed files with 17 additions and 19 deletions

View File

@ -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

View File

@ -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/`_)

View File

@ -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: ''