highlight.js
highlight.js copied to clipboard
enh(swift) highlight function and macro call usage
Improve fidelity by highlighting function calls in addition to definitions. This is already done by javascript, for example.
| Before | After |
|---|---|
Changes
- Add
negativeLookaheadhelper tolib/regex - Highlight all function and method calls as
title.function(e.g.myFunction(),obj.myFunction()). - Highlight all freestanding macro calls as
title.function(e.g.#myMacro()). - There can be >=0 whitespace between the end of the function name and the parentheses, but newlines are not permitted. Encapsulate this in a new regex,
TRAILING_PAREN_REGEX - Built-ins still highlight as such but with exceptions for methods–where they are semantically no longer builtins.
- Most keywords can exist as both properties and methods (e.g.
obj.if()). Highlight keyword method calls also.- Number sign keywords and attribute keywords are permitted as raw functions, as they start with leading
#and@respectively. If they don't start with these, they're no longer considered reserved.
- Number sign keywords and attribute keywords are permitted as raw functions, as they start with leading
- Highlight escaped function name calls also (e.g.
`myFunc`()). This feature exists so that reserved words can be used as identifiers. - Variable accesses (e.g.
obj.myVariable) remain unhighlighted for now. - Add markup tests for all the cases and edge cases described.
Next Steps (for a future PR)
- Support trailing closures, which are method calls:
exampleCall { print("action") }
Checklist
- [x] Added markup tests
- [x] Updated the changelog at
CHANGES.md
Build Size Report
Changes to minified artifacts in /build, after gzip compression.
4 files changed
Total change +241 B
View Changes
| file | base | pr | diff |
|---|---|---|---|
| es/core.min.js | 8.17 KB | 8.17 KB | +1 B |
| es/highlight.min.js | 8.17 KB | 8.17 KB | +1 B |
| es/languages/swift.min.js | 3.55 KB | 3.67 KB | +120 B |
| languages/swift.min.js | 3.56 KB | 3.68 KB | +119 B |
Build Size Report
Changes to minified artifacts in /build, after gzip compression.
3 files changed
Total change +231 B
View Changes
| file | base | pr | diff |
|---|---|---|---|
| es/languages/swift.min.js | 3.55 KB | 3.67 KB | +116 B |
| highlight.min.js | 8.21 KB | 8.21 KB | -1 B |
| languages/swift.min.js | 3.56 KB | 3.68 KB | +116 B |
Build Size Report
Changes to minified artifacts in /build, after gzip compression.
5 files changed
Total change +241 B
View Changes
| file | base | pr | diff |
|---|---|---|---|
| es/core.min.js | 8.17 KB | 8.17 KB | +1 B |
| es/highlight.min.js | 8.17 KB | 8.17 KB | +1 B |
| es/languages/swift.min.js | 3.55 KB | 3.67 KB | +120 B |
| highlight.min.js | 8.21 KB | 8.21 KB | -1 B |
| languages/swift.min.js | 3.56 KB | 3.68 KB | +120 B |
Build Size Report
Changes to minified artifacts in /build, after gzip compression.
5 files changed
Total change +207 B
View Changes
| file | base | pr | diff |
|---|---|---|---|
| es/core.min.js | 8.17 KB | 8.18 KB | +2 B |
| es/highlight.min.js | 8.17 KB | 8.18 KB | +2 B |
| es/languages/swift.min.js | 3.55 KB | 3.65 KB | +101 B |
| highlight.min.js | 8.21 KB | 8.21 KB | +2 B |
| languages/swift.min.js | 3.56 KB | 3.66 KB | +100 B |
We can't use negative lookahead until v12 though because it's a breaking change. And I don't have a timetable on that yet.
@joshgoebel This is an adapted version of Javascript's implementation which is already using negative lookahead ( see here). My understanding was that only lookbehind is not allowed currently.
Build Size Report
Changes to minified artifacts in /build, after gzip compression.
5 files changed
Total change +207 B
View Changes
| file | base | pr | diff |
|---|---|---|---|
| es/core.min.js | 8.17 KB | 8.17 KB | +2 B |
| es/highlight.min.js | 8.17 KB | 8.17 KB | +2 B |
| es/languages/swift.min.js | 3.55 KB | 3.65 KB | +101 B |
| highlight.min.js | 8.2 KB | 8.21 KB | +2 B |
| languages/swift.min.js | 3.56 KB | 3.66 KB | +100 B |
@joshgoebel Is there a way forward for this PR? If the concern is a language-specific breaking change, the Swift language itself is already using negative lookahead as well, here.
Sorry for delay. I think title.function might not be correct though typically we consider anything after . hanging off of an identifier (likely an object) a property... if the function is "global" or standalone then it could get function.title. IE:
debug_it("hello world") # debug_it is `title.function` (seems to be global function call)
person.eat("sandwich") # `eat` is a property of person, that also appears to be a method/function
Thoughts?