Here is a dummy implementation of Swift lexer writter in pure swift.
Usage: swiftl [FILENAME]
Simply pass swift source as a first argument. The lexer will paste the token sequence into stdout.
~$ cat A.swift
import Foundation
extension CGRect {
/// Creates a rect with unnamed arguments.
public init(_ origin: CGPoint, _ size: CGSize) {
self.origin = origin
self.size = size
}
...
}
~$ swiftl A.swift > A.tokens
~$ cat A.tokens
KW_import Identifier("Foundation")
KW_extension Identifier("CGRect") Lbrace
KW_public KW_init Lparen KW__ Identifier("origin") Colon Identifier("CGPoint") Comma KW__ Identifier("size") Colon Identifier("CGSize") Rparen Lbrace
KW_self OpPeriod Identifier("origin") OpEqual Identifier("origin")
KW_self OpPeriod Identifier("size") OpEqual Identifier("size")
Rbrace
...
Rbrace EOF
Build sources using xcodebuild
. No additional dependencies.
swiftl is available under the MIT license. See the LICENSE file for more info.