PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/org/ooc/frontend/parser/UseParser.java

http://github.com/nddrylliog/ooc
Java | 47 lines | 36 code | 11 blank | 0 comment | 7 complexity | 1f0206d2059bd5de4020b2792ec89399 MD5 | raw file
 1package org.ooc.frontend.parser;
 2
 3import java.io.IOException;
 4
 5import org.ooc.frontend.BuildParams;
 6import org.ooc.frontend.model.NodeList;
 7import org.ooc.frontend.model.Use;
 8import org.ooc.frontend.model.tokens.Token;
 9import org.ooc.frontend.model.tokens.TokenReader;
10import org.ooc.frontend.model.tokens.Token.TokenType;
11import org.ooc.middle.UseDef;
12import org.ubi.CompilationFailedError;
13import org.ubi.SourceReader;
14
15public class UseParser {
16
17	public static boolean fill(SourceReader sReader, TokenReader reader,
18			NodeList<Use> uses, BuildParams params) throws CompilationFailedError, IOException {
19		
20		Token startToken = reader.peek();
21		if(startToken.type != TokenType.USE_KW) return false;
22		reader.skip();
23		
24		StringBuilder sb = new StringBuilder();
25		
26		while(true) {
27			
28			Token token = reader.read();
29			if(token.type == TokenType.LINESEP) {
30				UseDef useDef = UseDefParser.parse(sb.toString(), sReader, token, params);
31				uses.add(new Use(useDef, startToken));
32				break;
33			}
34			if(token.type == TokenType.COMMA) {
35				UseDef useDef = UseDefParser.parse(sb.toString(), sReader, token, params);
36				uses.add(new Use(useDef, startToken));
37				sb.setLength(0);
38			} else {
39				sb.append(token.get(sReader));
40			}
41			
42		}
43		return true;
44		
45	}
46
47}