Commit 126d653b authored by David Owens II's avatar David Owens II

Support escape code sequences. This change does not support unicode literals.

parent b4202273
Pipeline #1798 failed with stage
......@@ -149,7 +149,26 @@ final public class Lexer {
else if next.character == "\"" {
var content = ""
while let info = scanner.next() where info.character != "\"" {
content.append(info.character!)
if info.character == "\\" {
let escaped = scanner.next()
let char = escaped?.character
switch escaped?.character {
case _ where char == "t": content.append("\t"); break
case _ where char == "b": fatalError("Unsupported escape sequence: \\b")
case _ where char == "n": content.append("\n"); break
case _ where char == "r": content.append("\r"); break
case _ where char == "f": fatalError("Unsupported escape sequence: \\f")
case _ where char == "'": content.append("'"); break
case _ where char == "\"": content.append("\""); break
case _ where char == "\\": content.append("\\"); break
default:
fatalError("Unsupposed escape sequence: \\\(escaped?.character)")
}
}
else {
content.append(info.character!)
}
}
return Token(type: .StringLiteral, value: content, line: next.line, column: next.column)
......
;; This is the most basic of sample files.
(package
:name "basic"
:version "0.1.0-dev"
:tasks {
:build {
:tool "lldb-build"
:name "json-swift"
:description "This the \"the\" most important thing.\n\tDon\'t you think so?"
:output-type "lib"
:sources ["src/**.swift" "lib/**.swift"]
}
}
)
; End of the sample.
\ No newline at end of file
......@@ -19,7 +19,8 @@ import atpkg
class ParserTests: Test {
required init() {}
let tests = [
ParserTests.testBasic
ParserTests.testBasic,
ParserTests.testEscape
]
let filename = #file
......@@ -64,4 +65,49 @@ class ParserTests: Test {
try test.assert(source?.vector?[0].string == "src/**.swift")
try test.assert(source?.vector?[1].string == "lib/**.swift")
}
static func testEscape() throws {
let filepath = Path("tests/collateral/escape.atpkg")
guard let parser = try Parser(filepath: filepath) else {
try test.assert(false); return
}
let result = try parser.parse()
let name = result.properties["name"]
try test.assert(name != nil)
try test.assert(name?.string == "basic")
let version = result.properties["version"]
try test.assert(version != nil)
try test.assert(version?.string == "0.1.0-dev")
let tasks = result.properties["tasks"]
try test.assert(tasks != nil)
let build = tasks?.map?["build"]
try test.assert(build != nil)
let tool = build?.map?["tool"]
try test.assert(tool != nil)
try test.assert(tool?.string == "lldb-build")
let buildName = build?.map?["name"]
try test.assert(buildName != nil)
try test.assert(buildName?.string == "json-swift")
let description = build?.map?["description"]
try test.assert(description != nil)
try test.assert(description?.string == "This the \"the\" most important thing.\n\tDon\'t you think so?")
let outputType = build?.map?["output-type"]
try test.assert(outputType != nil)
try test.assert(outputType?.string == "lib")
let source = build?.map?["sources"]
try test.assert(source != nil)
try test.assert(source?.vector != nil)
try test.assert(source?.vector?[0].string == "src/**.swift")
try test.assert(source?.vector?[1].string == "lib/**.swift")
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment