Package wyc.io.WhileyFileLexer

Examples of wyc.io.WhileyFileLexer.Token


        filename.length() - 7);
    WhileyFile wf = new WhileyFile(pkg.append(name), filename);

    skipWhiteSpace();
    while (index < tokens.size()) {
      Token lookahead = tokens.get(index);
      if (lookahead.kind == Import) {
        parseImportDeclaration(wf);
      } else {
        List<Modifier> modifiers = parseModifiers();
        checkNotEof();
View Full Code Here


    int start = index;

    match(Import);

    // First, parse "from" usage (if applicable)
    Token token = tryAndMatch(true, Identifier, Star);
    if (token == null) {
      syntaxError("expected identifier or '*' here", token);
    }
    String name = token.text;
    // NOTE: we don't specify "from" as a keyword because this prevents it
    // from being used as a variable identifier.
    Token lookahead;
    if ((lookahead = tryAndMatchOnLine(Identifier)) != null) {
      // Ok, this must be "from"
      if (!lookahead.text.equals("from")) {
        syntaxError("expected \"from\" here", lookahead);
      }
View Full Code Here

    wf.add(new WhileyFile.Import(filter, name, sourceAttr(start, end - 1)));
  }

  private List<Modifier> parseModifiers() {
    ArrayList<Modifier> mods = new ArrayList<Modifier>();
    Token lookahead;
    boolean visible = false;
    while ((lookahead = tryAndMatch(true, Public, Protected, Private,
        Native, Export)) != null) {
      switch(lookahead.kind) {
      case Public:
View Full Code Here

      match(Function);
    } else {
      match(Method);
    }

    Token name = match(Identifier);

    // Parse function or method parameters
    match(LeftBrace);

    ArrayList<Parameter> parameters = new ArrayList<Parameter>();
    HashSet<String> environment = new HashSet<String>();

    boolean firstTime = true;
    while (eventuallyMatch(RightBrace) == null) {
      if (!firstTime) {
        match(Comma);
      }
      firstTime = false;
      int pStart = index;
      Pair<SyntacticType, Token> p = parseMixedType();
      Token id = p.second();
      if (environment.contains(id.text)) {
        syntaxError("parameter already declared", id);
      }
      parameters.add(wf.new Parameter(p.first(), id.text, sourceAttr(
          pStart, index - 1)));
      environment.add(id.text);
    }

    // Parse (optional) return type
    TypePattern ret;
    HashSet<String> ensuresEnvironment = environment;

    if (tryAndMatch(true, EqualsGreater) != null) {
      // Explicit return type is given, so parse it! We first clone the
      // environent and create a special one only for use within ensures
      // clauses, since these are the only expressions which may refer to
      // variables declared in the return type.
      ensuresEnvironment = new HashSet<String>(environment);
      ret = parseTypePattern(ensuresEnvironment, true);
    } else {
      // Return type is omitted, so it is assumed to be void
      SyntacticType vt = new SyntacticType.Void(sourceAttr(start,
          index - 1));
      ret = new TypePattern.Leaf(vt, null, sourceAttr(start, index - 1));
    }

    // Parse optional throws/requires/ensures clauses

    ArrayList<Expr> requires = new ArrayList<Expr>();
    ArrayList<Expr> ensures = new ArrayList<Expr>();
    // FIXME: following should be a list!
    SyntacticType throwws = new SyntacticType.Void();

    Token lookahead;
    while ((lookahead = tryAndMatch(true, Requires, Ensures, Throws)) != null) {
      switch (lookahead.kind) {
      case Requires:
        // NOTE: expression terminated by ':'
        requires.add(parseLogicalExpression(wf, environment, true));
View Full Code Here

    int start = index;
    // Match identifier rather than kind e.g. Type to avoid "type" being a
    // keyword.
    match(Identifier);
    //
    Token name = match(Identifier);
    match(Is);
    // Parse the type pattern
    TypePattern pattern = parseTypePattern(new HashSet<String>(), false);

    Expr constraint = null;
View Full Code Here

    // Match identifier rather than kind e.g. constant to avoid "constant"
    // being a
    // keyword.
    match(Identifier);
    //
    Token name = match(Identifier);
    match(Is);
    Expr e = parseMultiExpression(wf, new HashSet<String>(), false);
    int end = index;
    matchEndLine();
    WhileyFile.Declaration declaration = wf.new Constant(modifiers, e,
View Full Code Here

   * @return
   */
  private Indent getIndent() {
    skipEmptyLines();
    if (index < tokens.size()) {
      Token token = tokens.get(index);
      if (token.kind == Indent) {
        return new Indent(token.text, token.start);
      }
      return null;
    }
View Full Code Here

   * @return
   */
  private Stmt parseStatement(WhileyFile wf, HashSet<String> environment,
      Indent indent) {
    checkNotEof();
    Token lookahead = tokens.get(index);

    // First, attempt to parse the easy statement forms.

    switch (lookahead.kind) {
    case Assert:
View Full Code Here

    // Match case block
    List<Stmt.Catch> catches = new ArrayList<Stmt.Catch>();
    while (tryAndMatch(true, Catch) != null) {
      match(LeftBrace);
      SyntacticType type = parseType();
      Token id = match(Identifier);
      if (environment.contains(id.text)) {
        syntaxError("variable already declared", id);
      }
      HashSet<String> catchEnvironment = new HashSet<String>(environment);
      catchEnvironment.add(id.text);
View Full Code Here

   * @return
   */
  private Expr.LVal parseAccessLVal(WhileyFile wf, HashSet<String> environment) {
    int start = index;
    Expr.LVal lhs = parseLValTerm(wf, environment);
    Token token;

    while ((token = tryAndMatchOnLine(LeftSquare)) != null
        || (token = tryAndMatch(true, Dot, MinusGreater)) != null) {
      start = index;
      switch (token.kind) {
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.