]>
Commit | Line | Data |
---|---|---|
77d0155b RBR |
1 | extension Map { |
2 | static func parse(content: String) -> ParsedMap { | |
3 | ||
4 | let parsers = [ | |
fdb4633d | 5 | AnyMapParserStrategy(NoteParserStrategy()), |
77d0155b RBR |
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 | |
1b85f723 | 23 | } |
5e8ff485 | 24 | } |
1b85f723 | 25 | } |
5e8ff485 | 26 | |
77d0155b | 27 | return builder.build() |
5e8ff485 | 28 | } |
1b85f723 | 29 | } |