Skip to content

Commit

Permalink
Fix word-boundary regexs. (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Aug 28, 2023
1 parent fc33eb6 commit 3df5553
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 57 deletions.
58 changes: 29 additions & 29 deletions vscode/syntaxes/toit.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"repository": {
"import-section": {
"name": "meta.import.toit",
"begin": "^import\\b",
"begin": "^import(?!-)\\b",
"end": "^(?!\\s)",
"beginCaptures": {
"0": {
Expand All @@ -36,11 +36,11 @@
},
{
"name": "constant.language.import-export-all.show.toit",
"match": "\\bshow\\b"
"match": "\\b(?<!-)show(?!-)\\b"
},
{
"name": "constant.language.import-export-all.as.toit",
"match": "\\bas\\b"
"match": "\\b(?<!)as(?!-)\\b"
},
{
"name": "constant.language.import-export-all.import_all.toit",
Expand All @@ -50,7 +50,7 @@
},
"export-section": {
"name": "meta.export.toit",
"begin": "^export\\b",
"begin": "^export(?!-)\\b",
"end": "^(?!\\s)",
"beginCaptures": {
"0": {
Expand All @@ -69,7 +69,7 @@
},
"class-section": {
"name": "meta.class.toit",
"begin": "^(?:(abstract)[ ]+)?(class|monitor|interface)\\b",
"begin": "^(?:(abstract)[ ]+)?(class|monitor|interface)(?!-)\\b",
"end": "^(?=[^\\s/]|/[^/*])",
"beginCaptures": {
"1": {
Expand Down Expand Up @@ -98,7 +98,7 @@
},
{
"name": "meta.class.signature",
"begin": "(\\b\\w+\\b)",
"begin": "(\\b(?<!-)[\\w-]+(?!-)\\b)",
"end": ":",
"beginCaptures": {
"1": {
Expand All @@ -111,7 +111,7 @@
},
{
"name": "meta.extends.clause.toit",
"match": "\\b(extends)\\s+([\\p{L}_][\\w+-]*)\\b",
"match": "\\b(?<!-)(extends)\\s+([\\p{L}_][\\w-]*)(?!-)\\b",
"captures": {
"1": {
"name": "keyword.control.extends.toit"
Expand All @@ -123,11 +123,11 @@
},
{
"name": "keyword.control.extends.toit",
"match": "\\bextends\\b"
"match": "\\b(?<!-)extends(?!-)\\b"
},
{
"name": "keyword.control.implements.toit",
"match": "\\bimplements\\b"
"match": "\\b(?<!-)implements(?!-)\\b"
},
{
"include": "#type-name"
Expand Down Expand Up @@ -185,11 +185,11 @@
},
{
"name": "keyword.control.toit",
"match": "(\\bstatic\\b|\\babstract\\b|\\boperator\\b)"
"match": "\\b(?<!-)(static|abstract|operator)(?!-)\\b"
},
{
"name": "meta.member.signature",
"begin": "(\\bconstructor\\b)(\\.[\\p{L}_][\\w-]*)?|([\\p{L}_][\\w-]*[=]?|==|<<|>>>|>>|<=|>=|<|>|\\+|-|\\*|/|%|\\^|&|\\||\\[\\]\\=|\\[\\]|\\[\\.\\.\\])",
"begin": "(?<!-)\\b(constructor)(?!-)\\b(\\.[\\p{L}_][\\w-]*)?|([\\p{L}_][\\w-]*[=]?|==|<<|>>>|>>|<=|>=|<|>|\\+|-|\\*|/|%|\\^|&|\\||\\[\\]\\=|\\[\\]|\\[\\.\\.\\])",
"end": "(?=\\:(?![\\p{L}_])|^\\s{0,4}(?:[^\\s/]|/[^/*]))",
"beginCaptures": {
"1": {
Expand Down Expand Up @@ -333,31 +333,31 @@
"patterns": [
{
"name": "keyword.control.toit",
"match": "\\b(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)\\b"
"match": "\\b(?<!-)(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)(?!-)\\b"
},
{
"name": "keyword.control.pseudo.toit",
"match": "\\bunreachable\\b"
"match": "\\b(?<!-)unreachable(?!-)\\b"
},
{
"name": "keyword.control.type_check.toit",
"match": "\\b(is|as)\\b"
"match": "\\b(?<!-)(is|as)(?!-)\\b"
}
]
},
"invalid_non_expression": {
"patterns": [
{
"name": "invalid.illegal.non_expression.toit",
"match": "\\b(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)\\b"
"match": "\\b(?<!-)(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)(?!-)\\b"
},
{
"name": "invalid.illegal.non_expression.toit",
"match": "\\b(is|as)\\b"
"match": "\\b(?<!-)(is|as)(?!-)\\b"
},
{
"name": "invalid.illegal.non_expression.toit",
"match": "\\b(super|this)\\b"
"match": "\\b(?<!-)(super|this)(?!-)\\b"
}
]
},
Expand Down Expand Up @@ -544,11 +544,11 @@
"patterns": [
{
"name": "constant.language.toit",
"match": "\\b(null|true|false)\\b"
"match": "\\b(?<!-)(null|true|false)(?!-)\\b"
},
{
"name": "constant.numeric.capitalized_user_constants.toit",
"match": "\\b_*[A-Z](-?[A-Z0-9_])+\\b"
"match": "\\b(?<!-)_*[A-Z](-?[A-Z0-9_])+(?!-)\\b"
}
]
},
Expand Down Expand Up @@ -595,15 +595,15 @@
"patterns": [
{
"name": "constant.numeric.dec.toit",
"match": "(?<!\\w)-?([0-9](_(?=[0-9]))?)+\\b"
"match": "(?<!\\w)-?([0-9](_(?=[0-9]))?)+(?!-)\\b"
},
{
"name": "constant.numeric.dec.hex.toit",
"match": "(?<!\\w)-?0[xX]([0-9a-fA-F](_(?=[0-9a-fA-F]))?)+\\b"
"match": "(?<!\\w)-?0[xX]([0-9a-fA-F](_(?=[0-9a-fA-F]))?)+(?!-)\\b"
},
{
"name": "constant.numeric.dec.bin.toit",
"match": "(?<!\\w)-?0[bB]([01](_(?=[01]))?)+\\b"
"match": "(?<!\\w)-?0[bB]([01](_(?=[01]))?)+(?!-)\\b"
}
]
},
Expand Down Expand Up @@ -717,7 +717,7 @@
"patterns": [
{
"name": "variable.language.special.toit",
"match": "\\b(this|it|super)\\b"
"match": "\\b(?<!-)(this|it|super)(?!-)\\b"
}
]
},
Expand All @@ -737,35 +737,35 @@
"patterns": [
{
"name": "entity.name.type.toit",
"match": "\\b_?[A-Z][0-9]*\\b[?]?"
"match": "\\b(?<!-)_?[A-Z][0-9]*(?!-)\\b[?]?"
},
{
"name": "entity.name.type.toit",
"match": "\\b_?[A-Z][A-Z_-]*[a-z][\\w-]*\\b[?]?"
"match": "\\b(?<!-)_?[A-Z][A-Z_-]*[a-z][\\w-]*(?!-)\\b[?]?"
},
{
"name": "entity.name.type.shorts.toit",
"match": "\\b(int|bool|float|string)\\b[?]?"
"match": "\\b(?<!-)(int|bool|float|string)(?!-)\\b[?]?"
},
{
"name": "entity.name.type.any_none.toit",
"match": "\\b(any|none)\\b"
"match": "\\b(?<!-)(any|none)(?!-)\\b"
}
]
},
"variable": {
"patterns": [
{
"name": "entity.name.function.call.toit",
"match": "\\b[\\p{L}_][\\w-]*\\b"
"match": "\\b(?<!-)[\\p{L}_][\\w-]*(?!-)\\b"
}
]
},
"primitive": {
"patterns": [
{
"name": "support.function.builtin.toit",
"match": "\\#primitive\\b"
"match": "\\#primitive(?!-)\\b"
}
]
},
Expand Down
58 changes: 30 additions & 28 deletions vscode/syntaxes/toit.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ comment: >
# followed by any number of letters, digits, underscores or dashes. Toit actually doesn't
# allow multiple dashes in a row (or the dash to be the last character), but we don't
# enforce that here. The syntax highlighter only needs to render valid code correctly.
# For most `\b` (word-boundary) we use a negative-look-ahead or negative-look-behind
# to ensure that the boundary is not a dash: `(?!-)\b` or `(?<!-)\b`.

name: Toit

Expand All @@ -32,23 +34,23 @@ patterns:
repository:
import-section:
name: meta.import.toit
begin: ^import\b # Section starts with an `import` (no indentation).
begin: ^import(?!-)\b # Section starts with an `import` (no indentation).
end: ^(?!\s) # Ends a non-indented different section. (Note the negative look-ahead to avoid consuming the next token).
beginCaptures:
0:
name: constant.language.import-export-all.import.toit
patterns:
- include: "#comment"
- name: constant.language.import-export-all.show.toit
match: \bshow\b
match: \b(?<!-)show(?!-)\b
- name: constant.language.import-export-all.as.toit
match: \bas\b
match: \b(?<!)as(?!-)\b
- name: constant.language.import-export-all.import_all.toit
match: \*

export-section:
name: meta.export.toit
begin: ^export\b # Section starts with an `export` (no indentation).
begin: ^export(?!-)\b # Section starts with an `export` (no indentation).
end: ^(?!\s) # Ends a non-indented different section. (Note the negative look-ahead to avoid consuming the next token).
beginCaptures:
0:
Expand All @@ -60,7 +62,7 @@ repository:

class-section:
name: meta.class.toit
begin: ^(?:(abstract)[ ]+)?(class|monitor|interface)\b
begin: ^(?:(abstract)[ ]+)?(class|monitor|interface)(?!-)\b
end: ^(?=[^\s/]|/[^/*]) # Ends with a non-indented different section. (Note the negative look-ahead to avoid consuming the next token).
beginCaptures:
1:
Expand All @@ -80,24 +82,24 @@ repository:
# "inherited-class". Otherwise we just mark "extends" and "implements" as
# keywords and the rest as types.
- name: meta.class.signature
begin: (\b\w+\b)
begin: (\b(?<!-)[\w-]+(?!-)\b)
end: ":"
beginCaptures:
1:
name: storage.type.class.toit
patterns:
- include: "#comment"
- name: meta.extends.clause.toit
match: \b(extends)\s+([\p{L}_][\w+-]*)\b
match: \b(?<!-)(extends)\s+([\p{L}_][\w-]*)(?!-)\b
captures:
1:
name: keyword.control.extends.toit
2:
name: entity.other.inherited-class
- name: keyword.control.extends.toit
match: \bextends\b
match: \b(?<!-)extends(?!-)\b
- name: keyword.control.implements.toit
match: \bimplements\b
match: \b(?<!-)implements(?!-)\b
- include: "#type-name"

toplevel-section:
Expand Down Expand Up @@ -133,11 +135,11 @@ repository:
patterns:
- include: "#comment"
- name: keyword.control.toit
match: (\bstatic\b|\babstract\b|\boperator\b)
match: \b(?<!-)(static|abstract|operator)(?!-)\b
- name: meta.member.signature
# A constructor (potentially named), or a function, setter, or operator.
# We don't handle operators specially, and just require the symbols to be after some whitespace.
begin: (\bconstructor\b)(\.[\p{L}_][\w-]*)?|([\p{L}_][\w-]*[=]?|==|<<|>>>|>>|<=|>=|<|>|\+|-|\*|/|%|\^|&|\||\[\]\=|\[\]|\[\.\.\])
begin: (?<!-)\b(constructor)(?!-)\b(\.[\p{L}_][\w-]*)?|([\p{L}_][\w-]*[=]?|==|<<|>>>|>>|<=|>=|<|>|\+|-|\*|/|%|\^|&|\||\[\]\=|\[\]|\[\.\.\])
# Ends (and thus starts the body) with a ":" (unless that's for a block),
# or something that isn't intended by 4.
end: (?=\:(?![\p{L}_])|^\s{0,4}(?:[^\s/]|/[^/*]))
Expand Down Expand Up @@ -220,20 +222,20 @@ repository:
keyword:
patterns:
- name: keyword.control.toit
match: &keywords \b(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)\b
match: &keywords \b(?<!-)(assert|and|or|not|if|for|else|try|finally|call|while|break|continue|throw|static|abstract|return)(?!-)\b
- name: keyword.control.pseudo.toit
match: \bunreachable\b
match: \b(?<!-)unreachable(?!-)\b
- name: keyword.control.type_check.toit
match: \b(is|as)\b
match: \b(?<!-)(is|as)(?!-)\b

invalid_non_expression: # Some expressions that are not valid in the signature. These will be highlighted as red.
patterns:
- name: invalid.illegal.non_expression.toit
match: *keywords
- name: invalid.illegal.non_expression.toit
match: \b(is|as)\b
match: \b(?<!-)(is|as)(?!-)\b
- name: invalid.illegal.non_expression.toit
match: \b(super|this)\b
match: \b(?<!-)(super|this)(?!-)\b

expressions:
patterns:
Expand Down Expand Up @@ -333,9 +335,9 @@ repository:
constant:
patterns:
- name: constant.language.toit
match: \b(null|true|false)\b
match: \b(?<!-)(null|true|false)(?!-)\b
- name: constant.numeric.capitalized_user_constants.toit
match: \b_*[A-Z](-?[A-Z0-9_])+\b
match: \b(?<!-)_*[A-Z](-?[A-Z0-9_])+(?!-)\b

number:
name: constant.numeric.toit
Expand All @@ -361,11 +363,11 @@ repository:
number-decimal:
patterns:
- name: constant.numeric.dec.toit
match: (?<!\w)-?([0-9](_(?=[0-9]))?)+\b
match: (?<!\w)-?([0-9](_(?=[0-9]))?)+(?!-)\b
- name: constant.numeric.dec.hex.toit
match: (?<!\w)-?0[xX]([0-9a-fA-F](_(?=[0-9a-fA-F]))?)+\b
match: (?<!\w)-?0[xX]([0-9a-fA-F](_(?=[0-9a-fA-F]))?)+(?!-)\b
- name: constant.numeric.dec.bin.toit
match: (?<!\w)-?0[bB]([01](_(?=[01]))?)+\b
match: (?<!\w)-?0[bB]([01](_(?=[01]))?)+(?!-)\b

character:
patterns:
Expand Down Expand Up @@ -438,7 +440,7 @@ repository:
special-variable:
patterns:
- name: variable.language.special.toit
match: \b(this|it|super)\b
match: \b(?<!-)(this|it|super)(?!-)\b

named-arg:
patterns:
Expand All @@ -456,23 +458,23 @@ repository:
# - single capitalized character followed by a number -> also a type: `class C1`.
# - capitalized identifier with at least on lower-case character: a type.
- name: entity.name.type.toit
match: \b_?[A-Z][0-9]*\b[?]?
match: \b(?<!-)_?[A-Z][0-9]*(?!-)\b[?]?
- name: entity.name.type.toit
match: \b_?[A-Z][A-Z_-]*[a-z][\w-]*\b[?]?
match: \b(?<!-)_?[A-Z][A-Z_-]*[a-z][\w-]*(?!-)\b[?]?
- name: entity.name.type.shorts.toit
match: \b(int|bool|float|string)\b[?]?
match: \b(?<!-)(int|bool|float|string)(?!-)\b[?]?
- name: entity.name.type.any_none.toit
match: \b(any|none)\b
match: \b(?<!-)(any|none)(?!-)\b

variable:
patterns:
- name: entity.name.function.call.toit
match: \b[\p{L}_][\w-]*\b
match: \b(?<!-)[\p{L}_][\w-]*(?!-)\b

primitive:
patterns:
- name: support.function.builtin.toit
match: \#primitive\b
match: \#primitive(?!-)\b

comment:
patterns:
Expand Down

0 comments on commit 3df5553

Please sign in to comment.