PageRenderTime 16ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 32 lines | 26 code | 6 blank | 0 comment | 7 complexity | 68440fb0b9c129994da58e1e283a2d82 MD5 | raw file
 1package org.ooc.frontend.parser;
 2
 3import org.ooc.frontend.model.tokens.Token;
 4import org.ooc.frontend.model.tokens.TokenReader;
 5import org.ooc.frontend.model.tokens.Token.TokenType;
 6import org.ubi.CompilationFailedError;
 7import org.ubi.SourceReader;
 8
 9public class ExternParser {
10
11	public static String parse(SourceReader sReader, TokenReader reader) throws CompilationFailedError {
12		
13		String externName = null;
14		
15		if(reader.peek().type == TokenType.EXTERN_KW) {
16			reader.skip();
17			if(reader.peek().type == TokenType.OPEN_PAREN) {
18				reader.skip();
19				Token nameToken = reader.read();
20				externName = nameToken.get(sReader);
21				if(reader.read().type != TokenType.CLOS_PAREN) {
22					throw new CompilationFailedError(sReader.getLocation(reader.prev()),
23							"Expected closing parenthesis after extern specification, but got "+reader.peek());
24				}
25			} else {
26				externName = "";
27			}
28		}
29		return externName;
30	}
31	
32}