Skip to content

Instantly share code, notes, and snippets.

@g-mark
Last active December 1, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-mark/da763b98b33641b22e45ece8bdf8fc28 to your computer and use it in GitHub Desktop.
Save g-mark/da763b98b33641b22e45ece8bdf8fc28 to your computer and use it in GitHub Desktop.
Sytnax highlighting test
/*
| multi-line
| comment, with empty lines
| see: https://ww.com
*/
open class Blah: NSObject {
enum EmbedError: Error {
case invalidUrl
}
override init() {
super.init()
}
private var x: Int?
internal let y: Double = 123.456
lazy public var rawString1 = #"\\Hello \(y) \\World"#
internal lazy var rawString2 = #"\\Hello \(y) \\World"#
/// Handle the embed request.
/// - Parameter req: the request with the url to embed
@discardableResult
final func embed(_ req: Request, completion: @escaping (Int) -> Void) throws -> /* Int */ String {
guard let uri = req.query[String.self, at: "url"], !uri.isEmpty,
let url = URL(string: uri),
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
(components.scheme == "http" || components.scheme == "https") else {
return "invalid url"
}
#if swift(>=4.2)
// swift 4.2 only code here
#elseif swift(>=3.2)
#warning("message")
#error("message")
#endif
return "embed: \\(url)"
}
func foo(these numbers: Int...) { }
struct Donut {
var a: String
mutating func boo() { a = "a" }
}
// MARK: - this is the end
}
private let sampleCode =
"""
func test() {
print("This is a test.")
}
"""
private let anotherSample = """
func test() {
print("This is a \((0..<3).map(String.init).joined(separator: ".")).")
// empty line above - but this one is extra long so that I can test word-wrapping in a multiline string.
}
"""
@propertyWrapper
struct Bloated<T> {
var wrappedValue: T
let projectedValue: T
init(wrappedValue: T) {
self.wrappedValue = wrappedValue
self.projectedValue = wrappedValue
}
}
struct Bling {
@Bloated var zed = 42
func exposed() {
let temp = $zed
}
func `func`() {
}
}
@g-mark
Copy link
Author

g-mark commented Nov 25, 2019

The goal is to show as many Swift syntax things as possible. This is not meant to compile, or even make any sense 😉.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment