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