diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-09-10 22:42:47 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-09-10 22:42:47 -0700 |
| commit | b93d8979bd9ea4148ea7e1d08d00ca846e151cf1 (patch) | |
| tree | 5762fbe37037115cdcee606b110000ce16232fcc /bpeg.bpeg | |
| parent | 95ec009a7c6cfb2ae43e63e25744ff5f76b88bf5 (diff) | |
Misc. tweaks and visualization changes, capitalized some rules
Diffstat (limited to 'bpeg.bpeg')
| -rw-r--r-- | bpeg.bpeg | 78 |
1 files changed, 42 insertions, 36 deletions
@@ -1,60 +1,66 @@ # This is a file defining the BPEG grammar using BPEG syntax -grammar; -grammar = __ @[main-pattern]extended-pat __ *((__`;__) def) ?(`;__); -def = @[name]ref __ `= __ @[definition]extended-pat; +Grammar; +Grammar = __ @[main-pattern]extended-pat __ *((__`;__) Def) ?(`;__); +Def = @[name]Ref __ `= __ @[definition]extended-pat; # This is used for command line arguments: -string-grammar = *(`\ pat ?`; / .); +String-grammar = *(`\ pat ?`; / .); -pat = empty / dot / string / char-range / char / escape-range / escape / no / anything-but - / upto-and / repeat / after / before / capture / replace / ref / parens; +pat = Empty / Dot / String / Char-range / Char / Escape-range / Escape / No / Anything-but + / Upto-and / Repeat / After / Before / Capture / Replace / Ref / parens; -empty = `/ >(__ (`)/`})); -dot = `.; -string = ( - `" @[s]*(escape / ~`") `" - / `' @[s]*(escape / ~`') `' +Empty = `/ >(__ (`)/`})); +Dot = `.; +String = ( + `" @[s]*(Escape / ~`") `" + / `' @[s]*(Escape / ~`') `' ); -char-range = `` @[low]. `- @[high].; -char = `` @[s].; -escape-range = `\ @[low]escape-sequence `- @[high]escape-sequence; -escape = `\ @[s]escape-sequence; +Char-range = `` @[low]. `- @[high].; +Char = `` @[s].; +Escape-range = `\ @[low]escape-sequence `- @[high]escape-sequence; +Escape = `\ @[s]escape-sequence; escape-sequence = ( 1-3 `0-7 / `x 2 (`0-9/`a-f/`A-F) /`a/`b/`e/`n/`r/`t/`v / . / \n ); -no = `! _ @pat; -anything-but = `~ ?`~ _ @pat; -upto-and = `& ?`& _ @pat; -repeat = ( - @[min]int _ `- _ @[max]int - / @[min]{=>"0"} @[max]int _ `- - / @[min]int _ `+ @[max](/) - / @[min]@[max]int - / `+ @[min]{=>"1"} @[max](/) - / `* @[min]{=>"0"} @[max](/) - / `? @[min]{=>"0"} @[max]{=>"1"} +No = `! _ @pat; +Anything-but = `~ ?`~ _ @pat; +Upto-and = `& ?`& _ @pat; +Repeat = ( + @[min]int _ `- _ @[max]int + /{@[min]{=>"0"}=>} @[max]int _ `- + / @[min]int _ `+ @[max](/) + / @[min]@[max]int + /{@[min]{=>"1"}=>} `+ @[max](/) + /{@[min]{=>"0"}=>} `* @[max](/) + /{@[min]{=>"0"}=>} `? {@[max]{=>"1"}=>} ) _ @[repeat-pat]pat ?( __ `% __ @[sep]pat); -after = `< _ pat; -before = `> _ pat; -capture = `@ ?(_ `[ @[capture-name]ref `]) _ @[capture]pat; -replace = `{ __ ( - ?(@[replace-pat]extended-pat __) "=>" ?(__ @[replacement]string) +After = `< _ pat; +Before = `> _ pat; +Capture = `@ ?(_ `[ @[capture-name]Ref `]) _ @[capture]pat; +Replace = `{ __ ( + ?(@[replace-pat]extended-pat __) "=>" ?(__ @[replacement]String) ) __ `}; -ref = @[name]( +Ref = @[name]( "^^" / "^" / "__" / "_" / "$$" / "$" / (`a-z/`A-Z) *(`a-z/`A-Z/`0-9/`-)); parens = `( __ extended-pat __ `); -chain = +@pat % (__); -otherwise = +@(chain/pat) % (__`/__); -extended-pat = otherwise / chain / pat; +Chain = +@pat % (__); +Otherwise = +@(Chain/pat) % (__`/__); +extended-pat = Otherwise / Chain / pat; -_ = *(` / \t); +# Special-symbol rules: +_ = *(` / \t); __ = *(` / \t / \r / \n / comment); +$$ = !$.; +$ = !.; +^^ = !<$.; +^ = !<.; + hash-comment = `# *.; # Note: comments are undefined by default in regular BPEG |
