Package wycs.io.WyalFileLexer

Examples of wycs.io.WyalFileLexer.Token


  }

  public Expr.Variable 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.Variable(id.text, sourceAttr(start, index - 1));
    } else {
      return null;
    }
View Full Code Here


  }

  private SyntacticType parseBaseType(HashSet<String> generics) {
    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

   *
   * @return
   */
  private Pair<SyntacticType, Expr.Variable> parseMixedType(
      HashSet<String> generics) {
    Token lookahead;
    int start = index;

    if ((lookahead = tryAndMatch(true, Function)) != 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(generics));
        }

        SyntacticType ret;

        // Functions require a return type (since otherwise they are
        // just nops)
        match(EqualsGreater);
        // Third, parse the return type
        ret = parseUnitType(generics);

        // Fourth, parse the optional throws type
        SyntacticType throwsType = null;
        if (tryAndMatch(true, Throws) != null) {
          throwsType = parseType(generics);
        }

        // Done
        SyntacticType type = new SyntacticType.Function(ret,
            throwsType, paramTypes, sourceAttr(start, index - 1));

        return new Pair<SyntacticType, Expr.Variable>(type,
            new Expr.Variable(id.text, sourceAttr(id.start,
                id.end())));
      } 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(generics);
    Token id = match(Identifier);
    return new Pair<SyntacticType, Expr.Variable>(type, new Expr.Variable(
        id.text, sourceAttr(id.start, id.end())));
  }
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

   * @param kind
   * @return
   */
  private Token eventuallyMatch(Token.Kind kind) {
    checkNotEof();
    Token token = tokens.get(index);
    if (token.kind != kind) {
      return null;
    } else {
      index = index + 1;
      return token;
View Full Code Here

    // skip all whitespace. Otherwise, we can't skip newlines as these are
    // significant.
    int next = terminated ? skipWhiteSpace(index) : skipLineSpace(index);

    if (next < tokens.size()) {
      Token t = tokens.get(next);
      for (int i = 0; i != kinds.length; ++i) {
        if (t.kind == kinds[i]) {
          index = next + 1;
          return t;
        }
View Full Code Here

   * @return
   */
  private Token tryAndMatchOnLine(Token.Kind kind) {
    int next = skipLineSpace(index);
    if (next < tokens.size()) {
      Token t = tokens.get(next);
      if (t.kind == kind) {
        index = next + 1;
        return t;
      }
    }
View Full Code Here

TOP

Related Classes of wycs.io.WyalFileLexer.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.