52 Commits

Author SHA1 Message Date
John Sundell
0b22fa3dcd
Fix highlighting for #available checks (#72)
This patch makes availability checks using `#available` highlight correctly,
by treating `#available` like a keyword.
2019-06-18 12:28:11 +02:00
John Sundell
d978081933
Add support for Swift 5.1’s opaque return types (#71)
This change adds support for the Swift 5.1 `some` keyword, which is used
to declare opaque return types.
2019-06-09 12:33:00 +02:00
John Sundell
6fcb458c63
Enable Splash to be compiled for iOS as a Swift Package (#70)
While Splash has supported iOS since its early days, this change makes
it possible to compile the iOS version as a Swift Package, using Xcode 11.

The changes require us to not make the assumption that != macOS == Linux.

(Also git ignore the new `.swiftpm` directory that SwiftPM now uses)
2019-06-09 11:56:10 +02:00
John Sundell
ec13df124a
Correctly highlight generic return types (#69)
This change makes Splash correctly highlight generics that are returned
from a function.
2019-05-13 11:25:16 +02:00
John Sundell
4675ffe963
Fix highlighting for inout closure arguments (#68)
This patch makes Splash correctly highlight the `inout` keyword when
it appears as part of a closure argument definition.
2019-05-13 11:19:15 +02:00
John Sundell
d01f7a6b2f
Correctly highlight closure argument shorthands (#66)
This patch makes Splash correctly highlight closure argument
shorthands (`$0`, `$1`, etc.), while also making the logic for
detecting a function call a bit simpler.
2019-04-14 22:17:47 +02:00
John Sundell
2b9e65e0d8
Fix highlighting for keywords used as generic function parameter labels (#65)
This patch fixes highlighting for parameter labels that also match a
keyword, when used within a generic function declaration.
2019-03-31 22:52:09 +02:00
John Sundell
c05038072a
Correctly highlight key paths passed as arguments (#64)
This makes Splash correctly highlight key paths that are passed as arguments
to a function, especially when there’s no external parameter label for that
argument.
2019-03-31 22:40:37 +02:00
John Sundell
b9177c4104
Fix highlighting for nested escaping closures (#62)
This patch makes Splash correctly highlight nested closures marked with
the `@escaping` attribute. The fix is to start treating `@` like a proper
token, rather than as a delimiter.
2019-03-24 11:35:33 +01:00
John Sundell
72837ce7f0
Correctly highlight the root level of a key path (#60)
When key path literals are used, Splash will now correctly highlight the
root level of that key path as a property, rather than as plain text.
2019-03-16 12:44:02 +01:00
John Sundell
2cdc99ce60
Correctly highlight generic parameters (#59)
This patch makes Splash highlight generics that appear as part of a
generic function’s parameter list in a correct way.
2019-03-16 12:41:53 +01:00
John Sundell
8e7599150f
Add SplashMarkdown (#57)
This change adds a new command line tool to the Splash family:
`SplashMarkdown`.

It’s an adapted version of the tool that I’ve been using for months to
publish every article on Swift by Sundell, and works by replacing all
code blocks within a Markdown file.

Adding this will hopefully make Splash even easier to use, without the
need for writing custom tooling, or to manually replace each code block
within a Markdown file with a “splashed” version.
2019-03-15 20:24:53 +01:00
Marco Capano
60c06cc385 Adding support for rethrows keyword (#56) 2019-03-12 23:12:54 +01:00
John Sundell
43f163bebc
Add test verifying that custom string interpolation works (#54)
Swift 5 enables us to define custom ways to interpolate expressions into
strings, and Splash already successfully highlights that syntax, but let’s
add a test to make sure that continues to be the case.
2019-03-12 00:52:18 +01:00
John Sundell
f1c56b342d
Add support for multi-line Swift 5 raw strings (#53)
This change extends the support for Swift 5 raw strings
to also cover multi-line literals.
2019-03-12 00:34:56 +01:00
John Sundell
6a75ec4491
Add support for Swift 5 single-line raw strings (#52)
This change makes Splash capable of highlighting Swift 5 raw strings,
although it’s currently limited to single line string literals. Support
for multi-line literals will be added in a future commit.
2019-03-12 00:21:25 +01:00
Marco Capano
9a7fdefab4 Adding nonmutating support (#50) 2019-03-11 21:31:32 +01:00
John Sundell
8bc46cbeb0
Add SwiftLint (#49)
This change adds SwiftLint to the project. For now, the rules are tweaked
to match the current state of the code base — but will over time be changed
back to their defaults in several cases.

Some smaller changes (mostly related to code style) were applied to the
project to remove all warnings.
2019-03-11 14:52:46 +01:00
Marco Capano
892d6ae39c adding support for "dynamic" keyword (#48)
* adding support for "dynamic" keyword

* adding test for linux

* Fixing alignment issue
2019-03-11 13:57:33 +01:00
John Sundell
18dd016aa1 Improve support for multi-line comments
This change enables Splash to highlight multi-line comments that begin
with two asterisks, rather than just one. A test has also been added to
verify that documentation-style multi-line comments with an asterisk on
each line are also highlighted correctly.
2019-03-11 00:40:57 +01:00
John Sundell
6dff287cd2 HTMLOutputFormat: Merge same-type tokens along with whitespace
This change makes Splash merge tokens of the same type (along with any
whitespace in between them) when generating HTML. The result is much
smaller HTML, since less tags have to be used to produce the same result.

This was most obvious with comment highlighting, for example, this comment:

```
// Hello I’m a comment
```

Would generate 5 different <span class="comment"></span> elements. Now
it’s just one!
2019-03-10 21:17:08 +01:00
John Sundell
59161f2724 Support function argument pre-processors
This change adds support for three pre-processors that can appear in
function delcarations: `#file`, `#line` and `#function`. They’re not
highlighted as pre-processors, but rather as keywords, to match the
way Xcode treats them.
2019-03-09 13:12:23 +01:00
John Sundell
d74074f409 Support switch statements with nil pattern matching
This change adds support for highlighting `nil` when
it occurs inside of a `switch` statement’s `case`.
2019-03-09 13:02:33 +01:00
John Sundell
d72e816cd8 Support ‘is’ keyword
This change makes Splash support the `is` keyword, for example in type
pattern matching in `switch` statements.
2019-03-08 22:04:10 +01:00
John Sundell
45ca85e299 Support the deinit keyword
This patch makes Splash correctly highlight the `deinit` keyword.
2019-03-08 21:57:56 +01:00
John Sundell
c85d8d9d4d Support highlighting of setters with an explicit access level
This change makes Splash correctly highlight property setters that have
an explicit access level defined — such as `private(set) var`.
2019-03-08 21:50:07 +01:00
John Sundell
9fbdb92edb Add special case for XCTAssert family of functions
Normally, we don’t want Splash to contain too many special cases for
individual symbol names — but the `XCTAssert` family of functions are
so common that it warrants it. The problem is that Splash would currently
highlight those functions as types, since they are capitalized, which
has now been changed to function calls instead.
2019-03-08 19:14:18 +01:00
John Sundell
f9ad32a0a6 Correctly highlight associated types
This patch makes Splash correctly highlight associated types within
protocol declarations. Like other declarations, typed declared using
the `associatedtype` keyword should not be highlighted.
2019-03-08 18:43:12 +01:00
John Sundell
45740696d0 Correctly highlight Bools passed as unnamed function arguments
This patch fixes highlighting of `Bool` values passed as arguments that
don’t have an external parameter label.
2019-03-08 18:32:12 +01:00
John Sundell
7f2421cd99 Correctly highlight types conforming to multiple protocols
Previously, the last protocol would be treated as a function call (Splash
thought it was a call with trailing closure syntax, rather than the opening
of a type definition). This patch fixes that by verifying that the code
checking for constraints inside a generic type definition is in fact looking
at a generic, rather than something else.
2019-03-08 18:20:36 +01:00
John Sundell
ddd2bf9020 Don’t treat keywords used as function names as keywords
Swift enables the use of keywords as function names, and we want those
to be treated as plain text (like other function names) rather than as
keywords. Some keywords require escaping using back-ticks, and this
patch accounts for both of those variations.
2019-03-08 17:55:44 +01:00
John Sundell
87437d7425 Don’t treat .init() as an enum
This change adds a special condition not to treat `.init()` as an enum
(or any other kind of dot access), just like we previously had for `self`.
2019-03-08 17:26:10 +01:00
John Sundell
5d075f7168 Add support for indirect enums
This patch makes Splash correctly highlight `indirect` enums. The keyword
was missing from the grammar definition.
2019-03-06 10:40:03 +01:00
John Sundell
4c6f71c0de Support custom token types
This change makes it possible to implement custom token types, which is
really useful when building specialized grammars that use non-standard
token types.
2018-09-28 14:02:42 +02:00
John Sundell
30b9300441 StatementTests: Nitpicky code style fixes 2018-09-06 08:41:50 +02:00
John Sundell
2a049c2031
Merge branch 'master' into patch-1 2018-09-05 23:32:15 +02:00
Marco Capano
2af2ec9d57
Fixing tests
This fixes a missing .whitespace in testForStatementWithContinue and handles indentation in testRepeatWhileStatement
2018-09-05 19:11:16 +02:00
Marco Capano
b8bc4ff2c3
Updating allTests static var 2018-09-05 18:45:53 +02:00
Marco Capano
3c638adcf5
Adding tests for repeat, while, continue and Fallthrough 2018-09-05 18:43:22 +02:00
Luffy
7a2f284e5d missed a component in the test declaration 2018-09-05 07:20:35 +05:30
Nikhil Muskur
70f49996fc
added the test case in allTests array 2018-09-05 07:06:01 +05:30
Nikhil Muskur
ea71fd7191
test added for the "inout" keyword 2018-09-05 06:58:51 +05:30
John Sundell
187effae29 DeclarationTests: Nitpicky code style fixes 2018-08-28 13:23:04 +02:00
wangchi
c1465b0a65 added “defer” as a keyword 2018-08-28 16:06:43 +08:00
John Sundell
ac9b512013 Don’t highlight keywords when used as a parameter label
Most keywords can be used as parameter labels, such as “for” or “in”, but
they shouldn’t be highlighted in that context.
2018-08-27 19:01:57 +02:00
John Sundell
dc83f92228 Highlight ‘self’ as keyword when used to refer to a type
This patch fixes syntax highlighting when using `.self` to refer to a type.
2018-08-27 18:44:07 +02:00
John Sundell
1faa928214 Correctly highlight subscript declarations
This patch fixes syntax highlighting when declaring
a subscript:

```
struct MyStruct {
	subscript(key: Key) -> Value? {
		…
	}
}
```
2018-08-27 18:32:22 +02:00
John Sundell
a86694802e Highlight enums used as subscripting keys
This patch fixes highlighting when an enum is used as a dictionary key, like this:

```
let value = dictionary[.key]
```
2018-08-27 18:14:17 +02:00
John Sundell
c73767a0bc HTMLOutputFormat: Escape < and > characters
This patch makes `HTMLOutputFormat` correctly escape all < and > characters
that occur in source code. Otherwise, a web browser rendering the resulting
HTML will interpret those characters as tags.
2018-08-27 00:14:48 +02:00
John Sundell
be35cef1ea Correctly handle static methods called on a generic type
This patch fixes syntax highlighting for the following scenario:

```
Type<GenericType>.call()
```

Highlighting generic types is especially tricky, since we want them to
be highlighted when appearing at the call site, like above - but we don’t
want to highlight them when they are being declared. Hopefully with this
fix all/most edge cases are covered.
2018-08-27 00:10:08 +02:00