mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Rename Swift to SwiftAST.
This commit is contained in:
parent
514a863547
commit
1d0a54d62a
@ -61,7 +61,7 @@ public func == (left: Doc, right: Doc) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
func == (left: Swift, right: Swift) -> Bool {
|
||||
func == (left: SwiftAST, right: SwiftAST) -> Bool {
|
||||
switch (left, right) {
|
||||
case let (.KeyValue(k1, v1), .KeyValue(k2, v2)):
|
||||
return k1 == k2 && v1 == v2
|
||||
|
@ -1,8 +1,8 @@
|
||||
enum Swift: Equatable {
|
||||
enum SwiftAST: Equatable {
|
||||
case Atom(String)
|
||||
case Symbol(String, [String])
|
||||
case KeyValue(String, String)
|
||||
case Branch(String, [Swift])
|
||||
case Branch(String, [SwiftAST])
|
||||
|
||||
struct Parsers {
|
||||
static let alphabetic = ^"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".characters
|
||||
@ -12,10 +12,10 @@ enum Swift: Equatable {
|
||||
static let atom = concat <^> not(ws <|> ^")")+
|
||||
static let quoted = join(^"'", join((concat <^> not(^"'")*), ^"'"))
|
||||
|
||||
static let symbol = Swift.Symbol <^> (join(^"\"", join((concat <^> not(^"\"")*), ^"\"")) <*> (^"<" *> interpolate(concat <^> alphabetic+, ^"," <* ws*) <* ^">"))
|
||||
static let symbol = SwiftAST.Symbol <^> (join(^"\"", join((concat <^> not(^"\"")*), ^"\"")) <*> (^"<" *> interpolate(concat <^> alphabetic+, ^"," <* ws*) <* ^">"))
|
||||
static let keyValue = KeyValue <^> (word <* ^"=" <*> (quoted <|> atom))
|
||||
static let branch: String -> State<Swift>? = Branch <^> (^"(" *> ws* *> word <* ws* <*> sexpr* <* ws* <* ^")")
|
||||
static let sexpr = delay { (branch <|> symbol <|> keyValue <|> (Swift.Atom <^> atom)) <* ws* }
|
||||
static let branch: String -> State<SwiftAST>? = Branch <^> (^"(" *> ws* *> word <* ws* <*> sexpr* <* ws* <* ^")")
|
||||
static let sexpr = delay { (branch <|> symbol <|> keyValue <|> (SwiftAST.Atom <^> atom)) <* ws* }
|
||||
|
||||
static let root = ws* *> sexpr*
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
final class SwiftTests: XCTestCase {
|
||||
func testValuesCanBeAlphabetic() {
|
||||
XCTAssertEqual(full(Swift.Parsers.keyValue)("key=value"), .KeyValue("key", "value"))
|
||||
XCTAssertEqual(full(SwiftAST.Parsers.keyValue)("key=value"), .KeyValue("key", "value"))
|
||||
}
|
||||
|
||||
func testKeyValueCanBeQuoted() {
|
||||
XCTAssertEqual(full(Swift.Parsers.keyValue)("key='value'"), .KeyValue("key", "'value'"))
|
||||
XCTAssertEqual(full(SwiftAST.Parsers.keyValue)("key='value'"), .KeyValue("key", "'value'"))
|
||||
}
|
||||
|
||||
func testQuotedMatchesQuotedStrings() {
|
||||
XCTAssertEqual(full(Swift.Parsers.quoted)("'value'"), "'value'")
|
||||
XCTAssertEqual(full(SwiftAST.Parsers.quoted)("'value'"), "'value'")
|
||||
}
|
||||
|
||||
func testBranchesStartWithAnIdentifier() {
|
||||
XCTAssertEqual(full(Swift.Parsers.branch)("(a b=c)"), .Branch("a", [ .KeyValue("b", "c") ]))
|
||||
XCTAssertEqual(full(SwiftAST.Parsers.branch)("(a b=c)"), .Branch("a", [ .KeyValue("b", "c") ]))
|
||||
}
|
||||
|
||||
func testBranchesDoNotRequireChildren() {
|
||||
XCTAssertEqual(full(Swift.Parsers.branch)("(return_stmt)"), .Branch("return_stmt", []))
|
||||
XCTAssertEqual(full(SwiftAST.Parsers.branch)("(return_stmt)"), .Branch("return_stmt", []))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user