Created
October 11, 2017 07:15
Revisions
-
santoshrajan created this gist
Oct 11, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import Foundation typealias ParseResult = (output: Any, rest: Substring)? func stringParser(input: Substring) -> ParseResult { if input[input.startIndex] != "\"" { return nil } var isEscape = true func inspectChar(char: Character) -> Bool { if char == "\"" && !isEscape { return true } if char == "\\" { isEscape = true } else { isEscape = false } return false } if let index = input.index(where: inspectChar) { return (input[input.index(after: input.startIndex)...input.index(before: index)], input[input.index(after: index)...]) } return nil }