PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 32 lines | 24 code | 8 blank | 0 comment | 4 complexity | e76e3a3a9fba15487f0398329f191e91 MD5 | raw file
 1package org.ooc.frontend.parser;
 2
 3import org.ooc.frontend.model.Expression;
 4import org.ooc.frontend.model.Module;
 5import org.ooc.frontend.model.Return;
 6import org.ooc.frontend.model.ValuedReturn;
 7import org.ooc.frontend.model.tokens.Token;
 8import org.ooc.frontend.model.tokens.TokenReader;
 9import org.ooc.frontend.model.tokens.Token.TokenType;
10import org.ubi.SourceReader;
11
12public class ReturnParser {
13
14	public static Return parse(Module module, SourceReader sReader, TokenReader reader) {
15
16		int mark = reader.mark();
17		
18		Token startToken = reader.read();
19		if(startToken.type == TokenType.RETURN_KW) {
20			Expression expr = ExpressionParser.parse(module, sReader, reader);
21			if(expr == null) {
22				return new Return(startToken);
23			}
24			return new ValuedReturn(expr, startToken);
25		}
26		
27		reader.reset(mark);
28		return null;
29		
30	}
31	
32}