Package com.stuffwithstuff.magpie.ast.pattern

Examples of com.stuffwithstuff.magpie.ast.pattern.MatchCase


    String temp = parser.generateName();
    Expr value = Expr.var(left.getPosition(), false, temp, left);
    Expr truthCheck = Expr.call(left.getPosition(), value, Name.IS_TRUE);
   
    List<MatchCase> cases = new ArrayList<MatchCase>();
    cases.add(new MatchCase(Pattern.value(Expr.bool(true)), Expr.name(temp)));
    cases.add(new MatchCase(right));
   
    return Expr.match(left.getPosition().union(right.getPosition()),
        truthCheck, cases);
  }
View Full Code Here


    String temp = parser.generateName();
    Expr value = Expr.var(left.getPosition(), false, temp, left);
    Expr truthCheck = Expr.call(left.getPosition(), value, Name.IS_TRUE);
   
    List<MatchCase> cases = new ArrayList<MatchCase>();
    cases.add(new MatchCase(Pattern.value(Expr.bool(true)), right));
    cases.add(new MatchCase(Expr.name(temp)));
   
    return Expr.match(left.getPosition().union(right.getPosition()),
        truthCheck, cases);
  }
View Full Code Here

  // TODO(bob): Hackish. Eliminate.
  public static Expr if_(Expr condition, Expr thenExpr, Expr elseExpr) {
    if (elseExpr == null) elseExpr = Expr.nothing();
   
    List<MatchCase> cases = new ArrayList<MatchCase>();
    cases.add(new MatchCase(Pattern.value(Expr.bool(true)), thenExpr));
    cases.add(new MatchCase(elseExpr));
   
    return match(Position.surrounding(condition, elseExpr),
        condition,
        cases);
  }
View Full Code Here

   
    throw new IllegalArgumentException("Not a valid expression object.");
  }
 
  private MatchCase convertMatchCase(Obj matchCase) {
    return new MatchCase(
        getPattern(matchCase, "pattern"),
        getExpr(matchCase, "body"));
  }
View Full Code Here

    }
   
    // Parse the else case, if present.
    if (match(TokenType.ELSE)) {
      Expr elseCase = parseExpressionOrBlock();
      cases.add(new MatchCase(elseCase));
    }
   
    consume(TokenType.LINE);
    consume(TokenType.END);
   
View Full Code Here

        (lookAhead(TokenType.LINE, TokenType.CASE) ||
         lookAhead(TokenType.LINE, TokenType.ELSE))) {
      consume(TokenType.LINE);
    }
   
    return new MatchCase(pattern, bodyParse.getKey());
  }
View Full Code Here

    // Desugar to a match.
    // TODO(bob): Should do this in a later pass.
    Expr truthyCondition = Expr.call(condition.getPosition(), condition,
        Name.IS_TRUE);
    List<MatchCase> cases = new ArrayList<MatchCase>();
    cases.add(new MatchCase(Pattern.value(Expr.bool(true)), thenExpr));
    cases.add(new MatchCase(elseExpr));
   
    Expr matchExpr = Expr.match(span.end(), truthyCondition, cases);
    return allowExpressionAfterBlock(matchExpr);
  }
View Full Code Here

    // Allow newlines to separate single-line catches.
    if ((body.getValue() == null) && lookAhead(TokenType.LINE, TokenType.CATCH)) {
      consume();
    }

    return new MatchCase(pattern, body.getKey());
  }
View Full Code Here

TOP

Related Classes of com.stuffwithstuff.magpie.ast.pattern.MatchCase

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.