Skip to content

Conversation

@msanders
Copy link
Contributor

@msanders msanders commented May 14, 2018

This brings swift-mode's highlighting for built-ins up to par with TextMate’s Swift bundle. I’ve converted the regexes pertaining to built-ins from there for Swift 3 and up using pcre2el.

I've expanded the keyword regexes from there using exrex.generate in Python and applied them using regexpt-opt.

@taku0
Copy link
Member

taku0 commented May 15, 2018

Thank you for the PR. I will review this on the weekends.

@msanders msanders force-pushed the ms/comprehensive-built-ins branch 6 times, most recently from 716136d to 903cbdf Compare May 17, 2018 13:25
Copy link
Member

@taku0 taku0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive. Where do those foundation type/member names come from? The documentation? The source? I want to know it to update them future.

font-lock-builtin-face)

(,(concat "\\.\\s-*"
(regexp-opt swift-mode:member-functions-trailing-closure 'words)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, should this be swift-mode:member-functions?

swift-mode:foundation-structs
swift-mode:protocols
swift-mode:structs
swift-mode:typealiases) 'words)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should swift-mode:enum-types be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

"weak" "willSet")
"Keywords reserved in particular contexts.")

(defconst swift-mode:build-config-keywords
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

1
font-lock-builtin-face)

(,(concat "\\(^Process\\.\\|[^_[:alnum:]]Process\\.\\|^CommandLine\\.\\|[^_[:alnum:]]CommandLine\\.\\)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just \\<...\\>? Should \\s-* be inserted around the dot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. This only matches fields pertaining to Process/CommandLine, but I suppose that would be simpler. I've updated it to be combined with the other properties.

@msanders
Copy link
Contributor Author

msanders commented May 19, 2018

Thanks @taku0! Foundation types were generated using this script against the Foundation header copy-pasted from Xcode (jump to definition on import Foundation). It unfortunately only includes native Swift types, not the bridged classes. Not sure how to generate those without parsing the Objective-C headers. TextMate's regexes were expanded using the following in Python:

print("'({})".format(" ".join('"{}"'.format(x) for x in exrex.generate(pattern))))
@taku0
Copy link
Member

taku0 commented May 20, 2018

All looks good. Could you squash commits, then I will merge it. Thank you!

* Expand regexes for built-ins * Update existing keywords to use regexp-opt for consistency * Move keyword comments to docstrings * Add compactMap * Add Foundation types * Address PR feedback * Simplify property matching
@msanders msanders force-pushed the ms/comprehensive-built-ins branch from 51cb369 to 869eff9 Compare May 20, 2018 14:39
@msanders
Copy link
Contributor Author

Done 👍

@taku0 taku0 merged commit 9809fb6 into swift-emacs:master May 26, 2018
@msanders msanders deleted the ms/comprehensive-built-ins branch May 26, 2018 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants