Package wyc.io.WhileyFileLexer

Examples of wyc.io.WhileyFileLexer.Token


      // examine what follows to see whether this is a cast or bracketed
      // expression. See JavaDoc comments above for more on this. What we
      // do is first skip any whitespace, and then see what we've got.
      int next = skipLineSpace(index);
      if (next < tokens.size()) {
        Token lookahead = tokens.get(next);

        switch (lookahead.kind) {
        case Null:
        case True:
        case False:
View Full Code Here


      if (!firstTime) {
        match(Comma);
      }
      firstTime = false;
      // Parse field name being constructed
      Token n = match(Identifier);
      // Check field name is unique
      if (keys.contains(n.text)) {
        syntaxError("duplicate tuple key", n);
      }
      match(Colon);
View Full Code Here

      if (!firstTime) {
        match(Comma);
      }
      firstTime = false;
      SyntacticType type = parseType();
      Token id = match(Identifier);
      if (environment.contains(id.text)) {
        syntaxError("duplicate variable or parameter name", id);
      }
      environment.add(id.text);
      parameters.add(wf.new Parameter(type, id.text, sourceAttr(p_start,
View Full Code Here

  private Expr parseAddressExpression(WhileyFile wf,
      HashSet<String> environment, boolean terminated) {

    int start = index;
    match(Ampersand);
    Token id = match(Identifier);

    // Check whether or not parameters are supplied
    if (tryAndMatch(terminated, LeftBrace) != null) {
      // Yes, parameters are supplied!
      match(LeftBrace);
View Full Code Here

  }

  public Expr.LocalVariable parseTypePatternVar(boolean terminated) {
    // Now, try and match the optional variable identifier
    int start = index;
    Token id = tryAndMatch(terminated, Identifier);
    if (id != null) {
      return new Expr.LocalVariable(id.text, sourceAttr(start, index - 1));
    } else {
      return null;
    }
View Full Code Here

  }

  private SyntacticType parseBaseType() {
    checkNotEof();
    int start = index;
    Token token = tokens.get(index);
    SyntacticType t;

    switch (token.kind) {
    case Void:
      return new SyntacticType.Void(sourceAttr(start, index++));
View Full Code Here

        match(RightCurly);
        isOpen = true;
        break;
      } else {
        p = parseMixedType();
        Token id = p.second();
        if (types.containsKey(id.text)) {
          syntaxError("duplicate record key", id);
        }
        types.put(id.text, p.first());
      }
View Full Code Here

   * </pre>
   *
   * @return
   */
  private Pair<SyntacticType, Token> parseMixedType() {
    Token lookahead;
    int start = index;

    if ((lookahead = tryAndMatch(true, Function, Method)) != null) {
      // At this point, we *might* have a mixed function / method type
      // definition. To disambiguate, we need to see whether an identifier
      // follows or not.
      Token id = tryAndMatch(true, Identifier);

      if (id != null) {
        // Yes, we have found a mixed function / method type definition.
        // Therefore, we continue to pass the remaining type parameters.

        ArrayList<SyntacticType> paramTypes = new ArrayList<SyntacticType>();
        match(LeftBrace);

        boolean firstTime = true;
        while (eventuallyMatch(RightBrace) == null) {
          if (!firstTime) {
            match(Comma);
          }
          firstTime = false;
          paramTypes.add(parseUnitType());
        }

        SyntacticType ret;

        if (lookahead.kind == Function) {
          // Functions require a return type (since otherwise they are
          // just nops)
          match(EqualsGreater);
          // Third, parse the return type
          ret = parseUnitType();

        } else if (tryAndMatch(true, EqualsGreater) != null) {
          // Third, parse the (optional) return type. Observe that
          // this is forced to be a
          // unit type. This means that any tuple return types must be
          // in braces. The reason for this is that a trailing comma
          // may be part of an enclosing record type and we must
          // disambiguate
          // this.
          ret = parseUnitType();
        } else {
          // If no return is given, then default to void.
          ret = new SyntacticType.Void();
        }
        // Fourth, parse the optional throws type
        SyntacticType throwsType = null;
        if (tryAndMatch(true, Throws) != null) {
          throwsType = parseType();
        }

        // Done
        SyntacticType type;
        if (lookahead.kind == Token.Kind.Function) {
          type = new SyntacticType.Function(ret, throwsType,
              paramTypes, sourceAttr(start, index - 1));
        } else {
          type = new SyntacticType.Method(ret, throwsType,
              paramTypes, sourceAttr(start, index - 1));
        }
        return new Pair<SyntacticType, Token>(type, id);
      } else {
        // In this case, we failed to match a mixed type. Therefore, we
        // backtrack and parse as two separate items (i.e. type
        // identifier).
        index = start; // backtrack
      }
    }

    // This is the normal case, where we expect an identifier to follow the
    // type.
    SyntacticType type = parseType();
    Token id = match(Identifier);
    return new Pair<SyntacticType, Token>(type, id);
  }
View Full Code Here

   * @param kind
   * @return
   */
  private Token match(Token.Kind kind) {
    checkNotEof();
    Token token = tokens.get(index++);
    if (token.kind != kind) {
      syntaxError("expecting \"" + kind + "\" here", token);
    }
    return token;
  }
View Full Code Here

   */
  private Token[] match(Token.Kind... kinds) {
    Token[] result = new Token[kinds.length];
    for (int i = 0; i != result.length; ++i) {
      checkNotEof();
      Token token = tokens.get(index++);
      if (token.kind == kinds[i]) {
        result[i] = token;
      } else {
        syntaxError("Expected \"" + kinds[i] + "\" here", token);
      }
View Full Code Here

TOP

Related Classes of wyc.io.WhileyFileLexer.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.