/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

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