Skip to content

Package: ListParser

ListParser

nameinstructionbranchcomplexitylinemethod
ListParser(TokenStream)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
create(TokenStream)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
parse(Token, Type)
M: 0 C: 40
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 9
100%
M: 0 C: 1
100%

Coverage

1: package de.fhdw.wtf.parser;
2:
3: import de.fhdw.wtf.common.ast.type.ListType;
4: import de.fhdw.wtf.common.ast.type.Type;
5: import de.fhdw.wtf.common.stream.TokenStream;
6: import de.fhdw.wtf.common.token.Token;
7:
8: /**
9: * Parser to parse the given TokenStream to {@link ListType}s.
10: */
11: final class ListParser {
12:         
13:         /**
14:          * TokenStream.
15:          */
16:         private final TokenStream stream;
17:         
18:         /**
19:          * Constructor of {@link ListParser}.
20:          *
21:          * @param stream
22:          * tokenStream
23:          */
24:         private ListParser(final TokenStream stream) {
25:                 this.stream = stream;
26:         }
27:         
28:         /**
29:          * FactoryMethod for {@link ListParser}.
30:          *
31:          * @param stream
32:          * tokenStream
33:          * @return The {@link ListParser}-Object.
34:          */
35:         static ListParser create(final TokenStream stream) {
36:                 return new ListParser(stream);
37:         }
38:         
39:         /**
40:          * Parses a series of tokens and creates a {@link ListType} from it. If the series of tokens does not match the
41:          * grammar an Exception will be thrown.
42:          *
43:          * @param firstToken
44:          * firstToken
45:          * @param isOf
46:          * isOf-Type
47:          * @return ListType
48:          */
49:         ListType parse(final Token firstToken, final Type isOf) {
50:                 ListType current = ListType.create(firstToken, isOf);
51:                 this.stream.removeFirst();
52:                 current.setLastToken(this.stream.peek());
53:•                while (this.stream.hasNext() && this.stream.peek().isAsteriskToken()) {
54:                         final ListType list = ListType.create(firstToken, current);
55:                         this.stream.removeFirst();
56:                         list.setLastToken(this.stream.peek());
57:                         current = list;
58:                 }
59:                 return current;
60:         }
61:         
62: }