Added | as alias for \b

This commit is contained in:
Bruce Hill 2021-07-30 20:23:18 -07:00
parent a6d6e39f3f
commit 9c05f880b0
13 changed files with 35 additions and 25 deletions

5
bp.1
View File

@ -189,8 +189,11 @@ An identifier character (e.g.\ alphanumeric characters or underscores).
An identifier character, not including numbers (e.g.\ alphabetic
characters or underscores).
.TP
\f[B]|\f[R]
A word boundary (i.e.\ the edge of a word).
.TP
\f[B]\[rs]b\f[R]
A word boundary.
Alias for \f[B]|\f[R] (word boundary)
.TP
\f[B]!\f[R] \f[I]pat\f[R]
Not \f[I]pat\f[R]

View File

@ -168,8 +168,11 @@ by the same indentation that occurs on the current line.
`\I`
: An identifier character, not including numbers (e.g. alphabetic characters or underscores).
`|`
: A word boundary (i.e. the edge of a word).
`\b`
: A word boundary.
: Alias for `|` (word boundary)
`!` *pat*
: Not *pat*

View File

@ -48,7 +48,7 @@ escape-sequence: (
)
No: `! (__@pat / (!)=>"Expected a pattern after the exclamation mark")
Nodent: "\N"
Word-boundary: "\b"
Word-boundary: `| / "\b"
Identifier-char: "\i"
Identifier-start: "\I"
Upto-and: ".." [__(`%/`=)__@second=simple-pat] [__@first=simple-pat]

View File

@ -14,7 +14,7 @@ string-escape: `\ (`x 2 Hex / 1-3 `0-7 / `u 1-4 Hex / .)
id: \I *\i
var: \I *\i
keyword: !"" # No keywords defined by default
word: \b +\i
word: | +\i
HEX: `0-9,A-F
Hex: `0-9,a-f,A-F
hex: `0-9,a-f

View File

@ -24,5 +24,5 @@ keyword:
"unsigned" / "using" / "virtual" / "void" / "volatile" / "wchar_t" / "while" / "xor" / "xor_eq"
function-def: ^_ 2+(id / keyword / anglebraces / `*) % __ parens (__`; / >(__`{))
function: function-def __ braces
macro: ^"#define"\b ..$ *(<`\ \n..$)
import: ^`#("include"/"import")\b __ (string / `<..`>)
macro: ^"#define"| ..$ *(<`\ \n..$)
import: ^`#("include"/"import")| __ (string / `<..`>)

View File

@ -17,5 +17,5 @@ keyword:
"volatile" / "while"
function-def: ^_ 2+(id / keyword / `*) % __ parens (__`; / >(__`{))
function: function-def __ braces
macro: ^"#define"\b ..$ *(<`\ \n..$)
import: ^"#include"\b __ (string / `<..`>)
macro: ^"#define"| ..$ *(<`\ \n..$)
import: ^"#include"| __ (string / `<..`>)

View File

@ -12,6 +12,6 @@ keyword:
"break" / "default" / "func" / "interface" / "select" / "case" / "defer" / "go" /
"map" / "struct" / "chan" / "else" / "goto" / "package" / "switch" / "const" /
"fallthrough" / "if" / "range" / "type" / "continue" / "for" / "import" / "return" / "var"
function-def: \b"func"\b __ id __ parens __ [id / parens] >(__`{)
function-def: |"func"| __ id __ parens __ [id / parens] >(__`{)
function: function-def __ braces
import: \b"import"\b __ (parens / string)
import: |"import"| __ (parens / string)

View File

@ -18,6 +18,6 @@ keyword:
"public" / "return" / "short" / "static" / "super" / "switch" / "synchronized" /
"this" / "throw" / "throws" / "transient" / "true" / "try" / "typeof" / "var" /
"void" / "volatile" / "while" / "with" / "yield"
function-def: \b"function"\b __ [id__] parens / (id / parens) __ "=>"
function-def: |"function"| __ [id__] parens / (id / parens) __ "=>"
function: function-def __ braces
import: \b"import"\b ..%braces (`; / $)
import: |"import"| ..%braces (`; / $)

View File

@ -9,7 +9,7 @@
comment: ";" ..$
string: `" ..%string-escape `"
list: parens
function-def: `(__"defun"\b__id
function-def: `(__"defun"|__id
function: function-def ..%parens `)
id-char: `A-Z,a-z,0-9,!,$,%,&,*,+,-,.,/,:,<,=,>,?,@,^,_,~
id: !<`A-Z,a-z,0-9,!,$,%,&,*,+,-,.,/,:,<,=,>,?,@,^,_,~ +`A-Z,a-z,0-9,!,$,%,&,*,+,-,.,/,:,<,=,>,?,@,^,_,~

View File

@ -13,11 +13,11 @@ keyword:
"and" / "break" / "do" / "else" / "elseif" / "end" / "false" / "for" /
"function" / "goto" / "if" / "in" / "local" / "nil" / "not" / "or" /
"repeat" / "return" / "then" / "true" / "until" / "while"
function-def: \b"function"\b[_id (*(`.id)[`:id])]_ parens
function-def: |"function"|[_id (*(`.id)[`:id])]_ parens
block: function / if-block / while-block / for-block / repeat-block / do-block
repeat-block: \b"repeat"\b ..%(comment/string/\n) (\b"until"\b)
do-block: \b"do"\b ..%(comment/string/block/\n) (\b"end"\b)
for-block: \b"for"\b ..%\n >(\b"do"\b) do-block
while-block: \b"while"\b ..%\n >(\b"do"\b) do-block
if-block: \b"if"\b ..%\n \b"then"\b ..%(comment/string/\n) (\b"end"\b)
function: function-def ..%(comment/string/block/\n) (\b"end"\b)
repeat-block: |"repeat"| ..%(comment/string/\n) (|"until"|)
do-block: |"do"| ..%(comment/string/block/\n) (|"end"|)
for-block: |"for"| ..%\n >(|"do"|) do-block
while-block: |"while"| ..%\n >(|"do"|) do-block
if-block: |"if"| ..%\n |"then"| ..%(comment/string/\n) (|"end"|)
function: function-def ..%(comment/string/block/\n) (|"end"|)

View File

@ -14,7 +14,7 @@ keyword: "and" / "as" / "assert" / "break" / "class" / "continue" / "def" /
"not" / "or" / "pass" / "raise" / "return" / "try" / "while" /
"with" / "yield"
class: class-def +(\N ..$)
class-def: ^_"class"\b_id[_parens]_`:
class-def: ^_"class"|_id[_parens]_`:
function: function-def +(\N ..$)
function-def: ^_"def"\b_id parens `:
import: ^_["from"\b ..%parens >(\b"import"\b)] \b"import"\b ..%parens $
function-def: ^_"def"|_id parens `:
import: ^_["from"| ..%parens >(|"import"|)] |"import"| ..%parens $

View File

@ -13,6 +13,6 @@ keyword:
"false" / "fn" / "for" / "if" / "impl" / "in" / "let" / "loop" / "match" /
"mod" / "move" / "mut" / "pub" / "ref" / "return" / "self" / "Self" / "static" /
"struct" / "super" / "trait" / "true" / "type" / "unsafe" / "use" / "where" / "while"
function-def: \b"fn"\b __ id __ parens __ ["->"__(id / parens)] >(__`{)
function-def: |"fn"| __ id __ parens __ ["->"__(id / parens)] >(__`{)
function: function-def __ braces
import: \b"use"\b _ *(id / braces) % "::" _ `;
import: |"use"| _ *(id / braces) % "::" _ `;

View File

@ -332,6 +332,10 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str)
return all;
}
// Word boundary
case '|': {
return new_pat(f, start, str, 0, 0, BP_WORD_BOUNDARY);
}
// String literal
case '"': case '\'': case '\002': {
char endquote = c == '\002' ? '\003' : c;