0001 import Foundation 0002 0003 struct Context{ 0004 let tokens
Parser.swift:13 typealias ContextValue = (context: Context, value: Yaml)Parser.swift:14 func createContextValue (context: Context) -> Yaml -> ContextValue {Parser.swift:17 func getContext (cv: ContextValue) -> Context {Parser.swift:25 let c = lift(Context(tokens))Parser.swift:36 return parseDocs([])(Context(tokens))Parser.swift:39 func parseDocs (acc: [Yaml]) -> Context -> Result<[Yaml]> {Parser.swift:57 func peekType (context: Context) -> TokenType {Parser.swift:61 func peekMatch (context: Context) -> String {Parser.swift:65 func advance (context: Context) -> Context {Parser.swift:65 func advance (context: Context) -> Context {Parser.swift:68 return Context(tokens, context.aliases)Parser.swift:71 func ignoreSpace (context: Context) -> Context {Parser.swift:71 func ignoreSpace (context: Context) -> Context {Parser.swift:78 func ignoreDocEnd (context: Context) -> Context {Parser.swift:78 func ignoreDocEnd (context: Context) -> Context {Parser.swift:85 func expect (type: TokenType, message: String) -> Context -> Result<Context> {Parser.swift:85 func expect (type: TokenType, message: String) -> Context -> Result<Context> {Parser.swift:93 func expectVersion (context: Context) -> Result<Context> {Parser.swift:93 func expectVersion (context: Context) -> Result<Context> {Parser.swift:100 func error (message: String) -> Context -> String {Parser.swift:107 func recreateText (string: String, context: Context) -> String {Parser.swift:114 func parseHeader (context: Context) -> Result<Context> {Parser.swift:114 func parseHeader (context: Context) -> Result<Context> {Parser.swift:115 return parseHeader(true)(Context(context.tokens, [:]))Parser.swift:118 func parseHeader (yamlAllowed: Bool) -> Context -> Result<Context> {Parser.swift:118 func parseHeader (yamlAllowed: Bool) -> Context -> Result<Context> {Parser.swift:146 func parse (context: Context) -> Result<ContextValue> {Parser.swift:257 func addAlias (name: String) -> Yaml -> Context -> Context {Parser.swift:257 func addAlias (name: String) -> Yaml -> Context -> Context {Parser.swift:262 return Context(context.tokens, aliases)Parser.swift:283 func checkKeyUniqueness (acc: [Yaml: Yaml]) -> (context: Context, key: Yaml)Parser.swift:292 func parseFlowSeq (context: Context) -> Result<ContextValue> {Parser.swift:298 func parseFlowSeq (acc: [Yaml]) -> Context -> Result<ContextValue> {Parser.swift:317 func parseFlowMap (context: Context) -> Result<ContextValue> {Parser.swift:323 func parseFlowMap (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:348 func parseBlockSeq (context: Context) -> Result<ContextValue> {Parser.swift:352 func parseBlockSeq (acc: [Yaml]) -> Context -> Result<ContextValue> {Parser.swift:373 func parseBlockMap (context: Context) -> Result<ContextValue> {Parser.swift:377 func parseBlockMap (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:393 func parseQuestionMarkKeyValue (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:413 func parseColonValueOrNil (context: Context) -> Result<ContextValue> {Parser.swift:420 func parseColonValue (context: Context) -> Result<ContextValue> {Parser.swift:427 func parseStringKeyValue (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:446 func parseString (context: Context) -> Result<ContextValue> {Parser.swift:467 func parseBlockMapOrString (context: Context) -> Result<ContextValue> {Parser.swift:494 func parseLiteral (context: Context) -> Result<ContextValue> {: [TokenMatch] 0005 let aliases
Parser.swift:8 self.tokens = tokensParser.swift:58 return context.tokens[0].typeParser.swift:62 return context.tokens[0].matchParser.swift:66 var tokens = context.tokensParser.swift:115 return parseHeader(true)(Context(context.tokens, [:]))Parser.swift:262 return Context(context.tokens, aliases)Parser.swift:470 return context.tokens[1].type != .Colon || matches(match, regex: regex("\n")): [String: Yaml] 0006 0007 init
Parser.swift:9 self.aliases = aliasesParser.swift:68 return Context(tokens, context.aliases)Parser.swift:243 let value = context.aliases[name]Parser.swift:260 var aliases = context.aliases(_ tokens: [TokenMatch], _ aliases: [String: Yaml] = [:]) { 0008 self.tokens = tokens 0009 self.aliases = aliases 0010 } 0011 } 0012 0013 typealias ContextValue
Parser.swift:25 let c = lift(Context(tokens))Parser.swift:36 return parseDocs([])(Context(tokens))Parser.swift:68 return Context(tokens, context.aliases)Parser.swift:115 return parseHeader(true)(Context(context.tokens, [:]))Parser.swift:262 return Context(context.tokens, aliases)= (context: Context, value: Yaml) 0014 func createContextValue
Parser.swift:14 func createContextValue (context: Context) -> Yaml -> ContextValue {Parser.swift:17 func getContext (cv: ContextValue) -> Context {Parser.swift:20 func getValue (cv: ContextValue) -> Yaml {Parser.swift:146 func parse (context: Context) -> Result<ContextValue> {Parser.swift:284 -> Result<ContextValue> {Parser.swift:292 func parseFlowSeq (context: Context) -> Result<ContextValue> {Parser.swift:298 func parseFlowSeq (acc: [Yaml]) -> Context -> Result<ContextValue> {Parser.swift:317 func parseFlowMap (context: Context) -> Result<ContextValue> {Parser.swift:323 func parseFlowMap (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:348 func parseBlockSeq (context: Context) -> Result<ContextValue> {Parser.swift:352 func parseBlockSeq (acc: [Yaml]) -> Context -> Result<ContextValue> {Parser.swift:373 func parseBlockMap (context: Context) -> Result<ContextValue> {Parser.swift:377 func parseBlockMap (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:393 func parseQuestionMarkKeyValue (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:413 func parseColonValueOrNil (context: Context) -> Result<ContextValue> {Parser.swift:420 func parseColonValue (context: Context) -> Result<ContextValue> {Parser.swift:427 func parseStringKeyValue (acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> {Parser.swift:446 func parseString (context: Context) -> Result<ContextValue> {Parser.swift:467 func parseBlockMapOrString (context: Context) -> Result<ContextValue> {Parser.swift:494 func parseLiteral (context: Context) -> Result<ContextValue> {(context: Context) -> Yaml -> ContextValue { 0015 return { value in (context, value) } 0016 } 0017 func getContext
Parser.swift:221 return createContextValue <^> c <*> vParser.swift:230 return createContextValue <^> c <*> vParser.swift:238 return createContextValue <^> c <*> v(cv: ContextValue) -> Context { 0018 return cv.context 0019 } 0020 func getValue
Parser.swift:29 >>- getContextParser.swift:50 >>- getContextParser.swift:217 let c = cv >>- getContextParser.swift:227 >>- getContextParser.swift:237 let c = addAlias(name) <^> v <*> (cv >>- getContext)Parser.swift:310 >>- getContextParser.swift:336 >>- getContextParser.swift:341 >>- getContextParser.swift:364 >>- getContextParser.swift:401 >>- getContextParser.swift:406 >>- getContextParser.swift:434 >>- getContextParser.swift:439 >>- getContext(cv: ContextValue) -> Yaml { 0021 return cv.value 0022 } 0023 0024 func parseDoc
Parser.swift:27 let v = cv >>- getValueParser.swift:48 >>- getValueParser.swift:219 >>- getValueParser.swift:225 let v = cv >>- getValueParser.swift:236 let v = cv >>- getValueParser.swift:308 let v = cv >>- getValueParser.swift:334 let k = ck >>- getValueParser.swift:339 let v = cv >>- getValueParser.swift:362 let v = cv >>- getValueParser.swift:399 let k = ck >>- getValueParser.swift:404 let v = cv >>- getValueParser.swift:432 let k = ck >>- getValueParser.swift:437 let v = cv >>- getValue(tokens: [TokenMatch]) -> Result<Yaml> { 0025 let c = lift(Context(tokens)) 0026 let cv = c >>=- parseHeader >>=- parse 0027 let v = cv >>- getValue 0028 return cv 0029 >>- getContext 0030 >>- ignoreDocEnd 0031 >>=- expect(TokenType.End, message: "expected end") 0032 >>| v 0033 } 0034 0035 func parseDocs
Yaml.swift:99 return tokenize(text) >>=- parseDocYaml.swift:109 >>=- parseDoc(tokens: [TokenMatch]) -> Result<[Yaml]> { 0036 return parseDocs([])(Context(tokens)) 0037 } 0038 0039 func parseDocs
Yaml.swift:103 return tokenize(text) >>=- parseDocsYaml.swift:120 >>=- parseDocs(acc: [Yaml]) -> Context -> Result<[Yaml]> { 0040 return { context in 0041 if peekType(context) == .End { 0042 return lift(acc) 0043 } 0044 let cv = lift(context) 0045 >>=- parseHeader 0046 >>=- parse 0047 let v = cv 0048 >>- getValue 0049 let c = cv 0050 >>- getContext 0051 >>- ignoreDocEnd 0052 let a = appendToArray(acc) <^> v 0053 return parseDocs <^> a <*> c |> join 0054 } 0055 } 0056 0057 func peekType
Parser.swift:36 return parseDocs([])(Context(tokens))Parser.swift:53 return parseDocs <^> a <*> c |> join(context: Context) -> TokenType { 0058 return context.tokens[0].type 0059 } 0060 0061 func peekMatch
Parser.swift:41 if peekType(context) == .End {Parser.swift:72 if ![.Comment, .Space, .NewLine].contains(peekType(context)) {Parser.swift:79 if ![.Comment, .Space, .NewLine, .DocEnd].contains(peekType(context)) {Parser.swift:87 let check = peekType(context) == typeParser.swift:108 if string.characters.count >= 50 || peekType(context) == .End {Parser.swift:120 switch peekType(context) {Parser.swift:147 switch peekType(context) {Parser.swift:252 return fail(error("unexpected type \(peekType(context))")(context))Parser.swift:300 if peekType(context) == .CloseSB {Parser.swift:325 if peekType(context) == .CloseCB {Parser.swift:354 if peekType(context) != .Dash {Parser.swift:379 switch peekType(context) {Parser.swift:414 if peekType(context) != .Colon {Parser.swift:447 switch peekType(context) {(context: Context) -> String { 0062 return context.tokens[0].match 0063 } 0064 0065 func advance
Parser.swift:94 let version = peekMatch(context)Parser.swift:111 return recreateText(string + peekMatch(context), context: advance(context))Parser.swift:162 let m = peekMatch(context)Parser.swift:168 let m = peekMatch(context) |> replace(regex("0o"), template: "")Parser.swift:174 let m = peekMatch(context) |> replace(regex("0x"), template: "")Parser.swift:180 let m = peekMatch(context)Parser.swift:194 let m = peekMatch(context) as NSStringParser.swift:233 let m = peekMatch(context)Parser.swift:241 let m = peekMatch(context)Parser.swift:450 let m = normalizeBreaks(peekMatch(context))Parser.swift:455 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))Parser.swift:459 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))Parser.swift:468 let match = peekMatch(context)Parser.swift:495 let literal = peekMatch(context)Parser.swift:506 let block = peekMatch(blockContext)(context: Context) -> Context { 0066 var tokens = context.tokens 0067 tokens.removeAtIndex(0) 0068 return Context(tokens, context.aliases) 0069 } 0070 0071 func ignoreSpace
Parser.swift:75 return ignoreSpace(advance(context))Parser.swift:82 return ignoreDocEnd(advance(context))Parser.swift:89 >>| lift(advance(context))Parser.swift:97 >>| lift(advance(context))Parser.swift:111 return recreateText(string + peekMatch(context), context: advance(context))Parser.swift:124 >>- advanceParser.swift:131 >>- advanceParser.swift:137 return lift(advance(context))Parser.swift:153 return lift((advance(context), nil))Parser.swift:156 return lift((advance(context), true))Parser.swift:159 return lift((advance(context), false))Parser.swift:165 return lift((advance(context), v))Parser.swift:171 return lift((advance(context), v))Parser.swift:177 return lift((advance(context), v))Parser.swift:182 return lift((advance(context), v))Parser.swift:185 return lift((advance(context), .Double(Double.infinity)))Parser.swift:188 return lift((advance(context), .Double(-Double.infinity)))Parser.swift:191 return lift((advance(context), .Double(Double.NaN)))Parser.swift:195 return lift((advance(context), .Double(m.doubleValue)))Parser.swift:224 let cv = parse(advance(context))Parser.swift:235 let cv = parse(advance(context))Parser.swift:246 >>| lift((advance(context), value ?? nil))Parser.swift:301 return lift((advance(context), .Array(acc)))Parser.swift:326 return lift((advance(context), .Dictionary(acc)))Parser.swift:358 >>- advanceParser.swift:452 return lift((advance(context), .String(folded)))Parser.swift:456 return lift((advance(context), .String(unescapeDoubleQuotes(foldFlow(m)))))Parser.swift:460 return lift((advance(context), .String(unescapeSingleQuotes(foldFlow(m)))))Parser.swift:496 let blockContext = advance(context)(context: Context) -> Context { 0072 if ![.Comment, .Space, .NewLine].contains(peekType(context)) { 0073 return context 0074 } 0075 return ignoreSpace(advance(context)) 0076 } 0077 0078 func ignoreDocEnd
Parser.swift:75 return ignoreSpace(advance(context))Parser.swift:150 return parse(ignoreSpace(context))Parser.swift:228 >>- ignoreSpaceParser.swift:304 >>- ignoreSpaceParser.swift:306 >>- ignoreSpaceParser.swift:311 >>- ignoreSpaceParser.swift:329 >>- ignoreSpaceParser.swift:331 >>- ignoreSpaceParser.swift:342 >>- ignoreSpaceParser.swift:360 >>- ignoreSpaceParser.swift:365 >>- ignoreSpaceParser.swift:367 >>- ignoreSpaceParser.swift:402 >>- ignoreSpaceParser.swift:407 >>- ignoreSpaceParser.swift:423 >>- ignoreSpaceParser.swift:435 >>- ignoreSpaceParser.swift:440 >>- ignoreSpace(context: Context) -> Context { 0079 if ![.Comment, .Space, .NewLine, .DocEnd].contains(peekType(context)) { 0080 return context 0081 } 0082 return ignoreDocEnd(advance(context)) 0083 } 0084 0085 func expect
Parser.swift:30 >>- ignoreDocEndParser.swift:51 >>- ignoreDocEndParser.swift:82 return ignoreDocEnd(advance(context))(type: TokenType, message: String) -> Context -> Result<Context> { 0086 return { context in 0087 let check = peekType(context) == type 0088 return `guard`(error(message)(context), check: check) 0089 >>| lift(advance(context)) 0090 } 0091 } 0092 0093 func expectVersion
Parser.swift:31 >>=- expect(TokenType.End, message: "expected end")Parser.swift:132 >>=- expect(TokenType.Space, message: "expected space")Parser.swift:229 >>=- expect(TokenType.Dedent, message: "expected dedent")Parser.swift:294 >>=- expect(TokenType.OpenSB, message: "expected [")Parser.swift:305 >>=- (acc.count == 0 ? lift : expect(TokenType.Comma, message: "expected comma"))Parser.swift:319 >>=- expect(TokenType.OpenCB, message: "expected {")Parser.swift:330 >>=- (acc.count == 0 ? lift : expect(TokenType.Comma, message: "expected comma"))Parser.swift:337 >>=- expect(TokenType.Colon, message: "expected colon")Parser.swift:359 >>=- expect(TokenType.Indent, message: "expected indent after dash")Parser.swift:366 >>=- expect(TokenType.Dedent, message: "expected dedent after dash indent")Parser.swift:396 >>=- expect(TokenType.QuestionMark, message: "expected ?")Parser.swift:422 >>=- expect(TokenType.Colon, message: "expected colon")Parser.swift:505 >>=- expect(TokenType.String, message: "expected scalar block")(context: Context) -> Result<Context> { 0094 let version = peekMatch(context) 0095 let check = ["1.1", "1.2"].contains(version) 0096 return `guard`(error("invalid yaml version")(context), check: check) 0097 >>| lift(advance(context)) 0098 } 0099 0100 func error
Parser.swift:133 >>=- expectVersion(message: String) -> Context -> String { 0101 return { context in 0102 let text = recreateText("", context: context) |> escapeErrorContext 0103 return "\(message), \(text)" 0104 } 0105 } 0106 0107 func recreateText
Parser.swift:88 return `guard`(error(message)(context), check: check)Parser.swift:96 return `guard`(error("invalid yaml version")(context), check: check)Parser.swift:129 return `guard`(error(err)(context), check: yamlAllowed)Parser.swift:140 return `guard`(error("expected ---")(context), check: yamlAllowed)Parser.swift:245 return `guard`(error(err)(context), check: value != nil)Parser.swift:252 return fail(error("unexpected type \(peekType(context))")(context))Parser.swift:287 return `guard`(error(err)(context), check: !acc.keys.contains(key))Parser.swift:463 return fail(error("expected string")(context))Parser.swift:502 let c = `guard`(error(error0)(context),Parser.swift:530 >>| `guard`(error(error1)(blockContext), check: !check1)Parser.swift:531 >>| `guard`(error(error2)(blockContext), check: !check2)(string: String, context: Context) -> String { 0108 if string.characters.count >= 50 || peekType(context) == .End { 0109 return string 0110 } 0111 return recreateText(string + peekMatch(context), context: advance(context)) 0112 } 0113 0114 func parseHeader
Parser.swift:102 let text = recreateText("", context: context) |> escapeErrorContextParser.swift:111 return recreateText(string + peekMatch(context), context: advance(context))(context: Context) -> Result<Context> { 0115 return parseHeader(true)(Context(context.tokens, [:])) 0116 } 0117 0118 func parseHeader
Parser.swift:26 let cv = c >>=- parseHeader >>=- parseParser.swift:45 >>=- parseHeader(yamlAllowed: Bool) -> Context -> Result<Context> { 0119 return { context in 0120 switch peekType(context) { 0121 0122 case .Comment, .Space, .NewLine: 0123 return lift(context) 0124 >>- advance 0125 >>=- parseHeader(yamlAllowed) 0126 0127 case .YamlDirective: 0128 let err = "duplicate yaml directive" 0129 return `guard`(error(err)(context), check: yamlAllowed) 0130 >>| lift(context) 0131 >>- advance 0132 >>=- expect(TokenType.Space, message: "expected space") 0133 >>=- expectVersion 0134 >>=- parseHeader(false) 0135 0136 case .DocStart: 0137 return lift(advance(context)) 0138 0139 default: 0140 return `guard`(error("expected ---")(context), check: yamlAllowed) 0141 >>| lift(context) 0142 } 0143 } 0144 } 0145 0146 func parse
Parser.swift:115 return parseHeader(true)(Context(context.tokens, [:]))Parser.swift:125 >>=- parseHeader(yamlAllowed)Parser.swift:134 >>=- parseHeader(false)(context: Context) -> Result<ContextValue> { 0147 switch peekType(context) { 0148 0149 case .Comment, .Space, .NewLine: 0150 return parse(ignoreSpace(context)) 0151 0152 case .Null: 0153 return lift((advance(context), nil)) 0154 0155 case .True: 0156 return lift((advance(context), true)) 0157 0158 case .False: 0159 return lift((advance(context), false)) 0160 0161 case .Int: 0162 let m = peekMatch(context) 0163 // will throw runtime error if overflows 0164 let v = Yaml.Int(parseInt(m, radix: 10)) 0165 return lift((advance(context), v)) 0166 0167 case .IntOct: 0168 let m = peekMatch(context) |> replace(regex("0o"), template: "") 0169 // will throw runtime error if overflows 0170 let v = Yaml.Int(parseInt(m, radix: 8)) 0171 return lift((advance(context), v)) 0172 0173 case .IntHex: 0174 let m = peekMatch(context) |> replace(regex("0x"), template: "") 0175 // will throw runtime error if overflows 0176 let v = Yaml.Int(parseInt(m, radix: 16)) 0177 return lift((advance(context), v)) 0178 0179 case .IntSex: 0180 let m = peekMatch(context) 0181 let v = Yaml.Int(parseInt(m, radix: 60)) 0182 return lift((advance(context), v)) 0183 0184 case .InfinityP: 0185 return lift((advance(context), .Double(Double.infinity))) 0186 0187 case .InfinityN: 0188 return lift((advance(context), .Double(-Double.infinity))) 0189 0190 case .NaN: 0191 return lift((advance(context), .Double(Double.NaN))) 0192 0193 case .Double: 0194 let m = peekMatch(context) as NSString 0195 return lift((advance(context), .Double(m.doubleValue))) 0196 0197 case .Dash: 0198 return parseBlockSeq(context) 0199 0200 case .OpenSB: 0201 return parseFlowSeq(context) 0202 0203 case .OpenCB: 0204 return parseFlowMap(context) 0205 0206 case .QuestionMark: 0207 return parseBlockMap(context) 0208 0209 case .StringDQ, .StringSQ, .String: 0210 return parseBlockMapOrString(context) 0211 0212 case .Literal: 0213 return parseLiteral(context) 0214 0215 case .Folded: 0216 let cv = parseLiteral(context) 0217 let c = cv >>- getContext 0218 let v = cv 0219 >>- getValue 0220 >>- { value in Yaml.String(foldBlock(value.string ?? "")) } 0221 return createContextValue <^> c <*> v 0222 0223 case .Indent: 0224 let cv = parse(advance(context)) 0225 let v = cv >>- getValue 0226 let c = cv 0227 >>- getContext 0228 >>- ignoreSpace 0229 >>=- expect(TokenType.Dedent, message: "expected dedent") 0230 return createContextValue <^> c <*> v 0231 0232 case .Anchor: 0233 let m = peekMatch(context) 0234 let name = m.substringFromIndex(m.startIndex.successor()) 0235 let cv = parse(advance(context)) 0236 let v = cv >>- getValue 0237 let c = addAlias(name) <^> v <*> (cv >>- getContext) 0238 return createContextValue <^> c <*> v 0239 0240 case .Alias: 0241 let m = peekMatch(context) 0242 let name = m.substringFromIndex(m.startIndex.successor()) 0243 let value = context.aliases[name] 0244 let err = "unknown alias \(name)" 0245 return `guard`(error(err)(context), check: value != nil) 0246 >>| lift((advance(context), value ?? nil)) 0247 0248 case .End, .Dedent: 0249 return lift((context, nil)) 0250 0251 default: 0252 return fail(error("unexpected type \(peekType(context))")(context)) 0253 0254 } 0255 } 0256 0257 func addAlias
Parser.swift:26 let cv = c >>=- parseHeader >>=- parseParser.swift:46 >>=- parseParser.swift:150 return parse(ignoreSpace(context))Parser.swift:224 let cv = parse(advance(context))Parser.swift:235 let cv = parse(advance(context))Parser.swift:307 >>=- parseParser.swift:338 >>=- parseParser.swift:361 >>=- parseParser.swift:397 >>=- parseParser.swift:424 >>=- parse(name: String) -> Yaml -> Context -> Context { 0258 return { value in 0259 return { context in 0260 var aliases = context.aliases 0261 aliases[name] = value 0262 return Context(context.tokens, aliases) 0263 } 0264 } 0265 } 0266 0267 func appendToArray
Parser.swift:237 let c = addAlias(name) <^> v <*> (cv >>- getContext)(array: [Yaml]) -> Yaml -> [Yaml] { 0268 return { value in 0269 return array + [value] 0270 } 0271 } 0272 0273 func putToMap
Parser.swift:52 let a = appendToArray(acc) <^> vParser.swift:312 let a = appendToArray(acc) <^> vParser.swift:368 let a = appendToArray(acc) <^> v(map: [Yaml: Yaml]) -> Yaml -> Yaml -> [Yaml: Yaml] { 0274 return { key in 0275 return { value in 0276 var map = map 0277 map[key] = value 0278 return map 0279 } 0280 } 0281 } 0282 0283 func checkKeyUniqueness
Parser.swift:343 let a = putToMap(acc) <^> k <*> vParser.swift:408 let a = putToMap(acc) <^> k <*> vParser.swift:441 let a = putToMap(acc) <^> k <*> v(acc: [Yaml: Yaml]) -> (context: Context, key: Yaml) 0284 -> Result<ContextValue> { 0285 return { (context, key) in 0286 let err = "duplicate key \(key)" 0287 return `guard`(error(err)(context), check: !acc.keys.contains(key)) 0288 >>| lift((context, key)) 0289 } 0290 } 0291 0292 func parseFlowSeq
Parser.swift:333 >>=- checkKeyUniqueness(acc)Parser.swift:398 >>=- checkKeyUniqueness(acc)Parser.swift:431 >>=- checkKeyUniqueness(acc)(context: Context) -> Result<ContextValue> { 0293 return lift(context) 0294 >>=- expect(TokenType.OpenSB, message: "expected [") 0295 >>=- parseFlowSeq([]) 0296 } 0297 0298 func parseFlowSeq
Parser.swift:201 return parseFlowSeq(context)(acc: [Yaml]) -> Context -> Result<ContextValue> { 0299 return { context in 0300 if peekType(context) == .CloseSB { 0301 return lift((advance(context), .Array(acc))) 0302 } 0303 let cv = lift(context) 0304 >>- ignoreSpace 0305 >>=- (acc.count == 0 ? lift : expect(TokenType.Comma, message: "expected comma")) 0306 >>- ignoreSpace 0307 >>=- parse 0308 let v = cv >>- getValue 0309 let c = cv 0310 >>- getContext 0311 >>- ignoreSpace 0312 let a = appendToArray(acc) <^> v 0313 return parseFlowSeq <^> a <*> c |> join 0314 } 0315 } 0316 0317 func parseFlowMap
Parser.swift:295 >>=- parseFlowSeq([])Parser.swift:313 return parseFlowSeq <^> a <*> c |> join(context: Context) -> Result<ContextValue> { 0318 return lift(context) 0319 >>=- expect(TokenType.OpenCB, message: "expected {") 0320 >>=- parseFlowMap([:]) 0321 } 0322 0323 func parseFlowMap
Parser.swift:204 return parseFlowMap(context)(acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> { 0324 return { context in 0325 if peekType(context) == .CloseCB { 0326 return lift((advance(context), .Dictionary(acc))) 0327 } 0328 let ck = lift(context) 0329 >>- ignoreSpace 0330 >>=- (acc.count == 0 ? lift : expect(TokenType.Comma, message: "expected comma")) 0331 >>- ignoreSpace 0332 >>=- parseString 0333 >>=- checkKeyUniqueness(acc) 0334 let k = ck >>- getValue 0335 let cv = ck 0336 >>- getContext 0337 >>=- expect(TokenType.Colon, message: "expected colon") 0338 >>=- parse 0339 let v = cv >>- getValue 0340 let c = cv 0341 >>- getContext 0342 >>- ignoreSpace 0343 let a = putToMap(acc) <^> k <*> v 0344 return parseFlowMap <^> a <*> c |> join 0345 } 0346 } 0347 0348 func parseBlockSeq
Parser.swift:320 >>=- parseFlowMap([:])Parser.swift:344 return parseFlowMap <^> a <*> c |> join(context: Context) -> Result<ContextValue> { 0349 return parseBlockSeq([])(context) 0350 } 0351 0352 func parseBlockSeq
Parser.swift:198 return parseBlockSeq(context)(acc: [Yaml]) -> Context -> Result<ContextValue> { 0353 return { context in 0354 if peekType(context) != .Dash { 0355 return lift((context, .Array(acc))) 0356 } 0357 let cv = lift(context) 0358 >>- advance 0359 >>=- expect(TokenType.Indent, message: "expected indent after dash") 0360 >>- ignoreSpace 0361 >>=- parse 0362 let v = cv >>- getValue 0363 let c = cv 0364 >>- getContext 0365 >>- ignoreSpace 0366 >>=- expect(TokenType.Dedent, message: "expected dedent after dash indent") 0367 >>- ignoreSpace 0368 let a = appendToArray(acc) <^> v 0369 return parseBlockSeq <^> a <*> c |> join 0370 } 0371 } 0372 0373 func parseBlockMap
Parser.swift:349 return parseBlockSeq([])(context)Parser.swift:369 return parseBlockSeq <^> a <*> c |> join(context: Context) -> Result<ContextValue> { 0374 return parseBlockMap([:])(context) 0375 } 0376 0377 func parseBlockMap
Parser.swift:207 return parseBlockMap(context)Parser.swift:472 : parseBlockMap(context)(acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> { 0378 return { context in 0379 switch peekType(context) { 0380 0381 case .QuestionMark: 0382 return parseQuestionMarkKeyValue(acc)(context) 0383 0384 case .String, .StringDQ, .StringSQ: 0385 return parseStringKeyValue(acc)(context) 0386 0387 default: 0388 return lift((context, .Dictionary(acc))) 0389 } 0390 } 0391 } 0392 0393 func parseQuestionMarkKeyValue
Parser.swift:374 return parseBlockMap([:])(context)Parser.swift:409 return parseBlockMap <^> a <*> c |> joinParser.swift:442 return parseBlockMap <^> a <*> c |> join(acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> { 0394 return { context in 0395 let ck = lift(context) 0396 >>=- expect(TokenType.QuestionMark, message: "expected ?") 0397 >>=- parse 0398 >>=- checkKeyUniqueness(acc) 0399 let k = ck >>- getValue 0400 let cv = ck 0401 >>- getContext 0402 >>- ignoreSpace 0403 >>=- parseColonValueOrNil 0404 let v = cv >>- getValue 0405 let c = cv 0406 >>- getContext 0407 >>- ignoreSpace 0408 let a = putToMap(acc) <^> k <*> v 0409 return parseBlockMap <^> a <*> c |> join 0410 } 0411 } 0412 0413 func parseColonValueOrNil
Parser.swift:382 return parseQuestionMarkKeyValue(acc)(context)(context: Context) -> Result<ContextValue> { 0414 if peekType(context) != .Colon { 0415 return lift((context, nil)) 0416 } 0417 return parseColonValue(context) 0418 } 0419 0420 func parseColonValue
Parser.swift:403 >>=- parseColonValueOrNil(context: Context) -> Result<ContextValue> { 0421 return lift(context) 0422 >>=- expect(TokenType.Colon, message: "expected colon") 0423 >>- ignoreSpace 0424 >>=- parse 0425 } 0426 0427 func parseStringKeyValue
Parser.swift:417 return parseColonValue(context)Parser.swift:436 >>=- parseColonValue(acc: [Yaml: Yaml]) -> Context -> Result<ContextValue> { 0428 return { context in 0429 let ck = lift(context) 0430 >>=- parseString 0431 >>=- checkKeyUniqueness(acc) 0432 let k = ck >>- getValue 0433 let cv = ck 0434 >>- getContext 0435 >>- ignoreSpace 0436 >>=- parseColonValue 0437 let v = cv >>- getValue 0438 let c = cv 0439 >>- getContext 0440 >>- ignoreSpace 0441 let a = putToMap(acc) <^> k <*> v 0442 return parseBlockMap <^> a <*> c |> join 0443 } 0444 } 0445 0446 func parseString
Parser.swift:385 return parseStringKeyValue(acc)(context)(context: Context) -> Result<ContextValue> { 0447 switch peekType(context) { 0448 0449 case .String: 0450 let m = normalizeBreaks(peekMatch(context)) 0451 let folded = m |> replace(regex("^[ \\t\\n]+|[ \\t\\n]+$"), template: "") |> foldFlow 0452 return lift((advance(context), .String(folded))) 0453 0454 case .StringDQ: 0455 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context))) 0456 return lift((advance(context), .String(unescapeDoubleQuotes(foldFlow(m))))) 0457 0458 case .StringSQ: 0459 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context))) 0460 return lift((advance(context), .String(unescapeSingleQuotes(foldFlow(m))))) 0461 0462 default: 0463 return fail(error("expected string")(context)) 0464 } 0465 } 0466 0467 func parseBlockMapOrString
Parser.swift:332 >>=- parseStringParser.swift:430 >>=- parseStringParser.swift:471 ? parseString(context)(context: Context) -> Result<ContextValue> { 0468 let match = peekMatch(context) 0469 // should spaces before colon be ignored? 0470 return context.tokens[1].type != .Colon || matches(match, regex: regex("\n")) 0471 ? parseString(context) 0472 : parseBlockMap(context) 0473 } 0474 0475 func foldBlock
Parser.swift:210 return parseBlockMapOrString(context)(block: String) -> String { 0476 let (body, trail) = block |> splitTrail(regex("\\n*$")) 0477 return (body 0478 |> replace(regex("^([^ \\t\\n].*)\\n(?=[^ \\t\\n])", options: "m"), template: "$1 ") 0479 |> replace( 0480 regex("^([^ \\t\\n].*)\\n(\\n+)(?![ \\t])", options: "m"), template: "$1$2") 0481 ) + trail 0482 } 0483 0484 func foldFlow
Parser.swift:220 >>- { value in Yaml.String(foldBlock(value.string ?? "")) }(flow: String) -> String { 0485 let (lead, rest) = flow |> splitLead(regex("^[ \\t]+")) 0486 let (body, trail) = rest |> splitTrail(regex("[ \\t]+$")) 0487 let folded = body 0488 |> replace(regex("^[ \\t]+|[ \\t]+$|\\\\\\n", options: "m"), template: "") 0489 |> replace(regex("(^|.)\\n(?=.|$)"), template: "$1 ") 0490 |> replace(regex("(.)\\n(\\n+)"), template: "$1$2") 0491 return lead + folded + trail 0492 } 0493 0494 func parseLiteral
Parser.swift:451 let folded = m |> replace(regex("^[ \\t\\n]+|[ \\t\\n]+$"), template: "") |> foldFlowParser.swift:456 return lift((advance(context), .String(unescapeDoubleQuotes(foldFlow(m)))))Parser.swift:460 return lift((advance(context), .String(unescapeSingleQuotes(foldFlow(m)))))(context: Context) -> Result<ContextValue> { 0495 let literal = peekMatch(context) 0496 let blockContext = advance(context) 0497 let chomps = ["-": -1, "+": 1] 0498 let chomp = chomps[literal |> replace(regex("[^-+]"), template: "")] ?? 0 0499 let indent = parseInt(literal |> replace(regex("[^1-9]"), template: ""), radix: 10) 0500 let headerPattern = regex("^(\\||>)([1-9][-+]|[-+]?[1-9]?)( |$)") 0501 let error0 = "invalid chomp or indent header" 0502 let c = `guard`(error(error0)(context), 0503 check: matches(literal, regex: headerPattern)) 0504 >>| lift(blockContext) 0505 >>=- expect(TokenType.String, message: "expected scalar block") 0506 let block = peekMatch(blockContext) 0507 |> normalizeBreaks 0508 let (lead, _) = block 0509 |> splitLead(regex("^( *\\n)* {1,}(?! |\\n|$)")) 0510 let foundIndent = lead 0511 |> replace(regex("^( *\\n)*"), template: "") 0512 |> count 0513 let effectiveIndent = indent > 0 ? indent : foundIndent 0514 let invalidPattern = 0515 regex("^( {0,\(effectiveIndent)}\\n)* {\(effectiveIndent + 1),}\\n") 0516 let check1 = matches(block, regex: invalidPattern) 0517 let check2 = indent > 0 && foundIndent < indent 0518 let trimmed = block 0519 |> replace(regex("^ {0,\(effectiveIndent)}"), template: "") 0520 |> replace(regex("\\n {0,\(effectiveIndent)}"), template: "\n") 0521 |> (chomp == -1 0522 ? replace(regex("(\\n *)*$"), template: "") 0523 : chomp == 0 0524 ? replace(regex("(?=[^ ])(\\n *)*$"), template: "\n") 0525 : { s in s } 0526 ) 0527 let error1 = "leading all-space line must not have too many spaces" 0528 let error2 = "less indented block scalar than the indicated level" 0529 return c 0530 >>| `guard`(error(error1)(blockContext), check: !check1) 0531 >>| `guard`(error(error2)(blockContext), check: !check2) 0532 >>| c 0533 >>- { context in (context, .String(trimmed))} 0534 } 0535 0536 func parseInt
Parser.swift:213 return parseLiteral(context)Parser.swift:216 let cv = parseLiteral(context)(string: String, radix: Int) -> Int { 0537 let (sign, str) = splitLead(regex("^[-+]"))(string) 0538 let multiplier = (sign == "-" ? -1 : 1) 0539 let ints = radix == 60 0540 ? toSexInts(str) 0541 : toInts(str) 0542 return multiplier * ints.reduce(0, combine: { acc, i in acc * radix + i }) 0543 } 0544 0545 func toSexInts
Parser.swift:164 let v = Yaml.Int(parseInt(m, radix: 10))Parser.swift:170 let v = Yaml.Int(parseInt(m, radix: 8))Parser.swift:176 let v = Yaml.Int(parseInt(m, radix: 16))Parser.swift:181 let v = Yaml.Int(parseInt(m, radix: 60))Parser.swift:499 let indent = parseInt(literal |> replace(regex("[^1-9]"), template: ""), radix: 10)Parser.swift:580 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) }Parser.swift:582 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) }Parser.swift:584 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) }(string: String) -> [Int] { 0546 return string.componentsSeparatedByString(":").map { 0547 c in Int(c) ?? 0 0548 } 0549 } 0550 0551 func toInts
Parser.swift:540 ? toSexInts(str)(string: String) -> [Int] { 0552 return string.unicodeScalars.map { 0553 c in 0554 switch c { 0555 case "0"..."9": return Int(c.value) - Int(UnicodeScalar("0").value) 0556 case "a"..."z": return Int(c.value) - Int(UnicodeScalar("a").value) + 10 0557 case "A"..."Z": return Int(c.value) - Int(UnicodeScalar("A").value) + 10 0558 default: fatalError("invalid digit \(c)") 0559 } 0560 } 0561 } 0562 0563 func normalizeBreaks
Parser.swift:541 : toInts(str)(s: String) -> String { 0564 return replace(regex("\\r\\n|\\r"), template: "\n")(s) 0565 } 0566 0567 func unwrapQuotedString
Parser.swift:450 let m = normalizeBreaks(peekMatch(context))Parser.swift:455 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))Parser.swift:459 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))Parser.swift:507 |> normalizeBreaks(s: String) -> String { 0568 return s[s.startIndex.successor()..<s.endIndex.predecessor()] 0569 } 0570 0571 func unescapeSingleQuotes
Parser.swift:455 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))Parser.swift:459 let m = unwrapQuotedString(normalizeBreaks(peekMatch(context)))(s: String) -> String { 0572 return replace(regex("''"), template: "'")(s) 0573 } 0574 0575 func unescapeDoubleQuotes
Parser.swift:460 return lift((advance(context), .String(unescapeSingleQuotes(foldFlow(m)))))(input: String) -> String { 0576 return input 0577 |> replace(regex("\\\\([0abtnvfre \"\\/N_LP])")) 0578 { $ in escapeCharacters[$[1]] ?? "" } 0579 |> replace(regex("\\\\x([0-9A-Fa-f]{2})")) 0580 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) } 0581 |> replace(regex("\\\\u([0-9A-Fa-f]{4})")) 0582 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) } 0583 |> replace(regex("\\\\U([0-9A-Fa-f]{8})")) 0584 { $ in String(UnicodeScalar(parseInt($[1], radix: 16))) } 0585 } 0586 0587 let escapeCharacters
Parser.swift:456 return lift((advance(context), .String(unescapeDoubleQuotes(foldFlow(m)))))= [ 0588 "0": "\0", 0589 "a": "\u{7}", 0590 "b": "\u{8}", 0591 "t": "\t", 0592 "n": "\n", 0593 "v": "\u{B}", 0594 "f": "\u{C}", 0595 "r": "\r", 0596 "e": "\u{1B}", 0597 " ": " ", 0598 "\"": "\"", 0599 "\\": "\\", 0600 "/": "/", 0601 "N": "\u{85}", 0602 "_": "\u{A0}", 0603 "L": "\u{2028}", 0604 "P": "\u{2029}" 0605 ] 0606
Parser.swift:578 { $ in escapeCharacters[$[1]] ?? "" }