Exemplo n.º 1
0
  @Override
  public void parse(IParserManager pm, IToken token) throws SyntaxError {
    int type = token.type();
    if (this.mode == VALUE) {
      if (ParserUtil.isIdentifier(type)) {
        if (token.next().type() == Symbols.OPEN_CURLY_BRACKET) {
          DWTNode node = new DWTNode(token.raw(), token.nameValue());
          this.valued.setValue(node);
          pm.popParser();
          pm.pushParser(new DWTParser(node), true);
          return;
        }

        this.valued.setValue(new DWTReference(token.raw(), token.nameValue()));
        pm.popParser();
        return;
      }
      if (type == Symbols.OPEN_SQUARE_BRACKET) {
        Array list = new Array(token);
        this.mode = LIST_END;
        this.valued.setValue(list);
        pm.pushParser(new ExpressionListParser(list));
        return;
      }

      IValue primitive = ParserUtil.parsePrimitive(token, type);
      if (primitive != null) {
        this.valued.setValue(primitive);
        pm.popParser();
        return;
      }

      throw new SyntaxError(token, "Invalid Property Value");
    }
    if (this.mode == LIST_END) {
      pm.popParser();
      if (type == Symbols.CLOSE_SQUARE_BRACKET) {
        return;
      }
      throw new SyntaxError(token, "Invalid List - ']' expected", true);
    }
  }
Exemplo n.º 2
0
  @Override
  public void parse(IParserManager pm, IToken token) throws SyntaxError {
    int type = token.type();
    if (type == Symbols.SEMICOLON) {
      this.consumer.setImport(this.theImport);
      pm.popParser();
      return;
    }
    if (type == Symbols.COMMA || this.mode == 0) {
      this.consumer.setImport(this.theImport);
      pm.popParser(true);
      return;
    }
    if (this.mode == IMPORT) {
      if (type == Symbols.OPEN_CURLY_BRACKET) {
        MultiImport mi = new MultiImport(token);
        mi.setParent(this.theImport);
        this.theImport = mi;

        if (token.next().type() != Symbols.CLOSE_CURLY_BRACKET) {
          pm.pushParser(new ImportListParser(mi));
          this.mode = MULTIIMPORT;
          return;
        }
        this.mode = 0;
        pm.skip();
        return;
      }
      if (type == Symbols.WILDCARD) {
        PackageImport pi = new PackageImport(token.raw());
        pi.setParent(this.theImport);
        this.theImport = pi;
        this.mode = 0;
        return;
      }
      if (type == Keywords.ANNOTATION) {
        SimpleImport si = new SimpleImport(token.raw(), annotation);
        si.setParent(this.theImport);
        this.theImport = si;
        this.mode = DOT_ALIAS;
        return;
      }
      if (type == Keywords.TYPE) {
        SimpleImport si = new SimpleImport(token.raw(), ImportParser.type);
        si.setParent(this.theImport);
        this.theImport = si;
        this.mode = DOT_ALIAS;
        return;
      }
      if (ParserUtil.isIdentifier(type)) {
        SimpleImport si = new SimpleImport(token.raw(), token.nameValue());
        si.setParent(this.theImport);
        this.theImport = si;
        this.mode = DOT_ALIAS;
        return;
      }
      throw new SyntaxError(token, "Invalid Import Declaration - Identifier expected");
    }
    if (this.mode == DOT_ALIAS) {
      if (type == Symbols.DOT) {
        this.mode = IMPORT;
        return;
      }
      if (type == Symbols.ARROW_OPERATOR || type == Keywords.AS) {
        this.mode = 0;
        IToken next = token.next();
        if (ParserUtil.isIdentifier(next.type())) {
          this.theImport.setAlias(next.nameValue());
          pm.skip();
          return;
        }

        throw new SyntaxError(next, "Invalid Import Alias");
      }
      if (type == Symbols.CLOSE_CURLY_BRACKET) {
        this.consumer.setImport(this.theImport);
        pm.popParser(true);
        return;
      }

      throw new SyntaxError(token, "Invalid Import Declaration - '.' expected");
    }
    if (this.isInMode(MULTIIMPORT)) {
      this.theImport.expandPosition(token);
      this.consumer.setImport(this.theImport);
      pm.popParser();
      if (type == Symbols.CLOSE_CURLY_BRACKET) {
        return;
      }
      throw new SyntaxError(token, "Invalid Multi-Import - '}' expected");
    }
  }
Exemplo n.º 3
0
  @Override
  public void parse(IParserManager pm, IToken token) throws SyntaxError {
    int type = token.type();
    if (this.isInMode(MODIFIERS)) {
      int i = 0;
      if ((i = ModifierTypes.CLASS.parse(type)) != -1) {
        this.theClass.addModifier(i);
        return;
      }
      if ((i = ModifierTypes.CLASS_TYPE.parse(type)) != -1) {
        this.theClass.addModifier(i);
        this.theClass.setMetadata(
            IClass.getClassMetadata(this.theClass, this.theClass.getModifiers()));
        this.mode = NAME;
        return;
      }
      if (token.nameValue() == Name.at) {
        Annotation annotation = new Annotation(token.raw());
        this.theClass.addAnnotation(annotation);
        pm.pushParser(new AnnotationParser(annotation));
        return;
      }
    }
    if (this.isInMode(NAME)) {
      if (ParserUtil.isIdentifier(type)) {
        this.theClass.setPosition(token.raw());
        this.theClass.setName(token.nameValue());
        this.classList.addClass(this.theClass);
        this.mode = PARAMETERS | GENERICS | EXTENDS | IMPLEMENTS | BODY;
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - Name expected");
    }
    if (this.isInMode(PARAMETERS)) {
      if (type == Symbols.OPEN_PARENTHESIS) {
        pm.pushParser(new ParameterListParser(this.theClass));
        this.mode = PARAMETERS_END;
        return;
      }
    }
    if (this.isInMode(PARAMETERS_END)) {
      this.mode = GENERICS | EXTENDS | IMPLEMENTS | BODY;
      if (type == Symbols.CLOSE_PARENTHESIS) {
        return;
      }
      throw new SyntaxError(token, "Invalid Class Parameter List - ')' expected", true);
    }
    if (this.isInMode(GENERICS)) {
      if (type == Symbols.OPEN_SQUARE_BRACKET) {
        pm.pushParser(new TypeVariableListParser(this.theClass));
        this.theClass.setGeneric();
        this.mode = GENERICS_END;
        return;
      }
    }
    if (this.isInMode(GENERICS_END)) {
      this.mode = PARAMETERS | EXTENDS | IMPLEMENTS | BODY;
      if (type == Symbols.CLOSE_SQUARE_BRACKET) {
        return;
      }
      throw new SyntaxError(token, "Invalid Generic Type Variable List - ']' expected", true);
    }
    if (this.isInMode(EXTENDS)) {
      if (type == Keywords.EXTENDS) {
        if (this.theClass.hasModifier(Modifiers.INTERFACE_CLASS)) {
          pm.pushParser(new TypeListParser(this));
          this.mode = BODY;
          return;
        }

        pm.pushParser(new TypeParser(this));
        this.mode = IMPLEMENTS | BODY;
        return;
      }
    }
    if (this.isInMode(IMPLEMENTS)) {
      if (type == Keywords.IMPLEMENTS) {

        pm.pushParser(new TypeListParser(this));
        this.mode = BODY;

        if (this.theClass.hasModifier(Modifiers.INTERFACE_CLASS)) {
          throw new SyntaxError(
              token, "Interfaces cannot implement other interfaces - Use 'extends' instead");
        }
        return;
      }
    }
    if (this.isInMode(BODY)) {
      if (type == Symbols.OPEN_CURLY_BRACKET) {
        IClassBody body = new ClassBody(this.theClass);
        this.theClass.setBody(body);
        pm.pushParser(new ClassBodyParser(this.theClass, body));
        this.mode = BODY_END;
        return;
      }
      if (ParserUtil.isTerminator(type)) {
        if (token.isInferred()) {
          int nextType = token.next().type();
          switch (nextType) {
            case Keywords.EXTENDS:
              this.mode = EXTENDS;
              return;
            case Keywords.IMPLEMENTS:
              this.mode = IMPLEMENTS;
              return;
            case Symbols.OPEN_SQUARE_BRACKET:
              this.mode = GENERICS;
              return;
            case Symbols.OPEN_PARENTHESIS:
              this.mode = PARAMETERS;
              return;
          }
        }

        pm.popParser();
        this.theClass.expandPosition(token);
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - '{' or ';' expected", true);
    }
    if (this.isInMode(BODY_END)) {
      if (type == Symbols.CLOSE_CURLY_BRACKET) {
        pm.popParser();
        this.theClass.expandPosition(token);
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - '}' expected", true);
    }
  }