1 package de.fhdw.wtf.parser;
2
3 import de.fhdw.wtf.common.ast.Name;
4 import de.fhdw.wtf.common.ast.UnqualifiedName;
5 import de.fhdw.wtf.common.exception.parser.NoIdentifierException;
6 import de.fhdw.wtf.common.stream.TokenStream;
7
8
9
10
11 final class NameParser {
12
13
14
15
16 private final TokenStream stream;
17
18
19
20
21
22
23
24 private NameParser(final TokenStream stream) {
25 this.stream = stream;
26 }
27
28
29
30
31
32
33
34
35 static NameParser createNameParser(final TokenStream stream) {
36 return new NameParser(stream);
37 }
38
39
40
41
42
43
44
45
46 Name parse() throws NoIdentifierException {
47 Name newName = UnqualifiedName.create(ParserUtils.requireAndRemoveIdentifier(this.stream), this.stream.peek());
48
49 while (this.stream.hasNext() && this.stream.peek().isGreaterSymbolToken()) {
50 this.stream.removeFirst();
51 newName = newName.addName(ParserUtils.requireAndRemoveIdentifier(this.stream));
52 }
53 return newName;
54 }
55
56 }