]> git.r.bdr.sh - rbdr/map/blame - Map/Extensions/Map+parse.swift
Make delete a context action
[rbdr/map] / Map / Extensions / Map+parse.swift
CommitLineData
77d0155b
RBR
1extension 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
1b85f723 22 }
5e8ff485 23 }
1b85f723 24 }
5e8ff485 25
77d0155b 26 return builder.build()
5e8ff485 27 }
1b85f723 28}