Skip to content

Commit

Permalink
Fix highlighting identifier containing underscores and keywords
Browse files Browse the repository at this point in the history
Fixes #190
  • Loading branch information
taku0 committed Jan 4, 2024
1 parent 4891719 commit 8405965
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions swift-mode-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ This function does not search beyond LIMIT."
(< (point) limit)
(looking-at
(concat
"\\<\\("
"\\_<\\("
(string-join
'("func" "enum" "struct" "class" "protocol" "extension" "actor" "macro")
"\\|")
"\\)\\>"))))
"\\)\\_>"))))

(defun swift-mode:property-access-pos-p (pos limit)
"Return t if POS is just before the property name of a member expression.
Expand Down Expand Up @@ -350,7 +350,7 @@ The predicate MATCH-P is called with two arguments:
(while (and
(< (point) limit)
(not result)
(re-search-forward "\\<\\(\\sw\\|\\s_\\)+\\>" limit t))
(re-search-forward "\\_<\\(\\sw\\|\\s_\\)+\\_>" limit t))
(when (save-excursion
(save-match-data
(funcall match-p (match-beginning 0) limit)))
Expand Down Expand Up @@ -585,7 +585,7 @@ Excludes true, false, and keywords begin with a number sign.")
;; Attributes
"@\\(\\sw\\|\\s_\\)*"

(,(regexp-opt swift-mode:constant-keywords 'words)
(,(regexp-opt swift-mode:constant-keywords 'symbols)
.
'swift-mode:constant-keyword-face)

Expand All @@ -598,7 +598,7 @@ Excludes true, false, and keywords begin with a number sign.")
swift-mode:statement-keywords
swift-mode:expression-keywords
swift-mode:context-keywords)
'words)
'symbols)
.
'swift-mode:keyword-face)

Expand Down Expand Up @@ -634,13 +634,11 @@ Excludes true, false, and keywords begin with a number sign.")
.
'swift-mode:builtin-constant-face)

(,(regexp-opt swift-mode:build-config-keywords 'words)
(,(regexp-opt swift-mode:build-config-keywords 'symbols)
.
'swift-mode:build-config-keyword-face)

(,(concat "\\<"
(regexp-opt swift-mode:standard-precedence-groups 'non-nil)
"\\>")
(,(regexp-opt swift-mode:standard-precedence-groups 'symbols)
.
'swift-mode:builtin-precedence-group-face)

Expand All @@ -650,7 +648,7 @@ Excludes true, false, and keywords begin with a number sign.")
'swift-mode:function-name-face)

;; Method/function calls
("\\<\\(\\(\\sw\\|\\s_\\)+\\)\\>\\??\\s-*("
("\\_<\\(\\(\\sw\\|\\s_\\)+\\)\\_>\\??\\s-*("
1
'swift-mode:function-call-face)

Expand Down
2 changes: 1 addition & 1 deletion test/swift-files/font-lock/font-lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ foo !== bar // "foo !== bar"

a.b.c! // #("a.b.c!" 2 3 (face swift-mode:property-access-face) 4 5 (face swift-mode:property-access-face))

a.b.c_! // #("a.b.c_!" 2 3 (face swift-mode:property-access-face) 4 5 (face swift-mode:property-access-face))
a.b.c_! // #("a.b.c_!" 2 3 (face swift-mode:property-access-face) 4 6 (face swift-mode:property-access-face))

a.b.aあ! // #("a.b.a\343\201\202!" 2 3 (face swift-mode:property-access-face) 4 8 (face swift-mode:property-access-face))

Expand Down

0 comments on commit 8405965

Please sign in to comment.