Search in sources :

Example 11 with BLangMatch

use of org.wso2.ballerinalang.compiler.tree.statements.BLangMatch in project ballerina by ballerina-lang.

the class BLangPackageBuilder method createMatchNode.

public void createMatchNode(DiagnosticPos pos, Set<Whitespace> ws) {
    if (this.matchStmtStack == null) {
        this.matchStmtStack = new ArrayDeque<>();
    }
    BLangMatch matchStmt = (BLangMatch) TreeBuilder.createMatchStatement();
    matchStmt.pos = pos;
    matchStmt.addWS(ws);
    matchStmt.patternClauses = new ArrayList<>();
    this.matchStmtStack.addFirst(matchStmt);
}
Also used : BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch)

Example 12 with BLangMatch

use of org.wso2.ballerinalang.compiler.tree.statements.BLangMatch in project ballerina by ballerina-lang.

the class Desugar method generateIfElseStmt.

private BLangStatement generateIfElseStmt(BLangMatch matchStmt, BLangVariable matchExprVar) {
    List<BLangMatchStmtPatternClause> patterns = matchStmt.patternClauses;
    if (patterns.size() == 1) {
        return getMatchPatternBody(patterns.get(0), matchExprVar);
    }
    BLangIf parentIfNode = generateIfElseStmt(patterns.get(0), matchExprVar);
    BLangIf currentIfNode = parentIfNode;
    for (int i = 1; i < patterns.size(); i++) {
        if (i == patterns.size() - 1) {
            // This is the last pattern
            currentIfNode.elseStmt = getMatchPatternBody(patterns.get(i), matchExprVar);
        } else {
            currentIfNode.elseStmt = generateIfElseStmt(patterns.get(i), matchExprVar);
            currentIfNode = (BLangIf) currentIfNode.elseStmt;
        }
    }
    // 
    return parentIfNode;
}
Also used : BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangMatch (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch)7 BLangMatchStmtPatternClause (org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)3 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)3 ArrayList (java.util.ArrayList)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)2 BUnionType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 List (java.util.List)1 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)1 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)1 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)1 BJSONType (org.wso2.ballerinalang.compiler.semantics.model.types.BJSONType)1 BStructType (org.wso2.ballerinalang.compiler.semantics.model.types.BStructType)1 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)1