]> git.r.bdr.sh - rbdr/map/blob - Map/Extensions/Map+parse.swift
904f492cb49a063b0726b144b39c9caf305c375e
[rbdr/map] / Map / Extensions / Map+parse.swift
1 extension Map {
2 static func parse(content: String) -> ParsedMap {
3
4 let parsers = [
5 AnyMapParserStrategy(VertexParserStrategy()),
6 AnyMapParserStrategy(EdgeParserStrategy()),
7 AnyMapParserStrategy(BlockerParserStrategy()),
8 AnyMapParserStrategy(OpportunityParserStrategy()),
9 AnyMapParserStrategy(StageParserStrategy()),
10 ]
11 let builder = MapBuilder()
12
13 let lines = content.split(whereSeparator: \.isNewline)
14
15 for (index, line) in lines.enumerated() {
16 for parser in parsers {
17 if parser.canHandle(line: String(line)) {
18 let (type, object) = parser.handle(
19 index: index, line: String(line), vertices: builder.vertices)
20 builder.addObjectToMap(type: type, object: object)
21 break
22 }
23 }
24 }
25
26 return builder.build()
27 }
28 }