1 package de.fhdw.wtf.parser;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import de.fhdw.wtf.common.ast.Model;
7 import de.fhdw.wtf.common.exception.parser.AbstractParserException;
8 import de.fhdw.wtf.common.exception.parser.NoValidTokenStreamException;
9 import de.fhdw.wtf.common.stream.TokenStream;
10
11
12
13
14
15 public final class Parser {
16
17
18
19
20 private final TokenStream stream;
21
22
23
24
25 private final Collection<AbstractParserException> exceptions;
26
27
28
29
30
31
32
33 private Parser(final TokenStream stream) {
34 this.stream = stream;
35 this.exceptions = new ArrayList<>();
36 }
37
38
39
40
41
42
43
44
45 public static Parser create(final TokenStream stream) {
46 return new Parser(stream);
47 }
48
49
50
51
52
53
54
55
56
57 public Model parse() throws NoValidTokenStreamException {
58 final Model result = ModelParser.create(this.stream, this.exceptions).parse();
59 if (this.exceptions.size() > 0) {
60 throw NoValidTokenStreamException.create();
61 }
62 return result;
63 }
64
65
66
67
68
69
70 public Collection<AbstractParserException> getExceptions() {
71 return this.exceptions;
72 }
73 }