PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 59 lines | 46 code | 12 blank | 1 comment | 10 complexity | a182f35a4f215930cb68547718432bc3 MD5 | raw file
 1package org.ooc.frontend.parser;
 2
 3import org.ooc.frontend.model.FunctionCall;
 4import org.ooc.frontend.model.Module;
 5import org.ooc.frontend.model.tokens.Token;
 6import org.ooc.frontend.model.tokens.TokenReader;
 7import org.ooc.frontend.model.tokens.Token.TokenType;
 8import org.ooc.middle.OocCompilationError;
 9import org.ubi.CompilationFailedError;
10import org.ubi.SourceReader;
11
12public class FunctionCallParser {
13
14	public static FunctionCall parse(Module module, SourceReader sReader, TokenReader reader) {
15		
16		int mark = reader.mark();
17		
18		boolean superCall = false;
19		
20		Token tName = reader.read();
21		if(tName.get(sReader).equals("super")) {
22			if(reader.peek().type != TokenType.OPEN_PAREN) {
23				superCall = true;
24				tName = reader.read();
25			}
26		}
27		if(!tName.isNameToken()) {
28			reader.reset(mark);
29			return null;
30		}
31		String name = tName.get(sReader);
32		
33		String suffix = null;
34		if(reader.peek().type == TokenType.TILDE) {
35			reader.skip();
36			Token tSuff = reader.read();
37			if(tSuff.type != TokenType.NAME) {
38				throw new CompilationFailedError(sReader.getLocation(tSuff),
39				"Expecting suffix after 'functionname~' !");
40			}
41			suffix = tSuff.get(sReader);
42		}
43
44		FunctionCall call = new FunctionCall(name, suffix, tName);
45		if(superCall) {
46			throw new OocCompilationError(call, module, "Use of deprecated super-function call syntax.");
47			//call.setSuperCall(true);
48		}
49		
50		if(!ExpressionListFiller.fill(module, sReader, reader, call.getArguments())) {
51			reader.reset(mark);
52			return null; // not a function call
53		}
54		
55		return call;
56		
57	}
58	
59}