bp/grammars/builtins.bpeg

44 lines
1.2 KiB
Plaintext

# Meta-rules for acting on everything
pattern = !(/); # Not defined by default
replacement = {!(/)=>}; # Not defined by default
replace-all = +(...@replacement) ...;
find-all = {... >matching-line =>} +(matching-line/non-matching-line) ?{!<\n => "\n"};
only-matches = +{...@pattern=>'@1\n'};
matching-line = +(..@pattern)..$ ?\n;
non-matching-line = {..$=>};
# Helper definitions (commonly used)
crlf = \r\n;
cr = \r; r = \r;
anglebraces = `< *(anglebraces / ~~`>) `>;
brackets = `[ *(brackets / ~~`]) `];
braces = `{ *(braces / ~~`}) `};
parens = `( *(parens / ~~`)) `);
id = !<(`a-z/`A-Z/`_/`0-9) (`a-z/`A-Z/`_) *(`a-z/`A-Z/`_/`0-9);
word = !<(`a-z/`A-Z/`_/`0-9) +(`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);