diff --git a/bp.1 b/bp.1 index 8bab758..9a60593 100644 --- a/bp.1 +++ b/bp.1 @@ -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] diff --git a/bp.1.md b/bp.1.md index 1e02264..8e9482d 100644 --- a/bp.1.md +++ b/bp.1.md @@ -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* diff --git a/grammars/bp.bp b/grammars/bp.bp index 977fce8..3374f0c 100644 --- a/grammars/bp.bp +++ b/grammars/bp.bp @@ -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] diff --git a/grammars/builtins.bp b/grammars/builtins.bp index 437265c..23c8960 100644 --- a/grammars/builtins.bp +++ b/grammars/builtins.bp @@ -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 diff --git a/grammars/c++.bp b/grammars/c++.bp index 333e9f3..1814320 100644 --- a/grammars/c++.bp +++ b/grammars/c++.bp @@ -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 / `<..`>) diff --git a/grammars/c.bp b/grammars/c.bp index 015e5ed..03403eb 100644 --- a/grammars/c.bp +++ b/grammars/c.bp @@ -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 / `<..`>) diff --git a/grammars/go.bp b/grammars/go.bp index f86f2eb..f31e21c 100644 --- a/grammars/go.bp +++ b/grammars/go.bp @@ -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) diff --git a/grammars/javascript.bp b/grammars/javascript.bp index b59742c..438ddab 100644 --- a/grammars/javascript.bp +++ b/grammars/javascript.bp @@ -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 (`; / $) diff --git a/grammars/lisp.bp b/grammars/lisp.bp index f6f9796..b68cf71 100644 --- a/grammars/lisp.bp +++ b/grammars/lisp.bp @@ -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,!,$,%,&,*,+,-,.,/,:,<,=,>,?,@,^,_,~ diff --git a/grammars/lua.bp b/grammars/lua.bp index f75880e..6005514 100644 --- a/grammars/lua.bp +++ b/grammars/lua.bp @@ -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"|) diff --git a/grammars/python.bp b/grammars/python.bp index aab9a42..51c3c44 100644 --- a/grammars/python.bp +++ b/grammars/python.bp @@ -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 $ diff --git a/grammars/rust.bp b/grammars/rust.bp index a96062d..4df6b53 100644 --- a/grammars/rust.bp +++ b/grammars/rust.bp @@ -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) % "::" _ `; diff --git a/pattern.c b/pattern.c index 861efdf..785b45a 100644 --- a/pattern.c +++ b/pattern.c @@ -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;