Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support match-stmt for const-pattern and var capture-binding-pattern #25082

Merged
merged 20 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/ballerina-lang/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<Match>
<Package name="org.wso2.ballerinalang.compiler.tree" />
</Match>
<Match>
<Package name="org.wso2.ballerinalang.compiler.tree.bindingpatterns" />
</Match>
<Match>
<Package name="org.wso2.ballerinalang.compiler.tree.matchpatterns" />
</Match>
<Match>
<Package name="org.wso2.ballerinalang.compiler.parser" />
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.ballerinalang.model.clauses.InputClauseNode;
import org.ballerinalang.model.clauses.LetClauseNode;
import org.ballerinalang.model.clauses.LimitClauseNode;
import org.ballerinalang.model.clauses.MatchClauseNode;
import org.ballerinalang.model.clauses.OnClauseNode;
import org.ballerinalang.model.clauses.OnConflictClauseNode;
import org.ballerinalang.model.clauses.OnFailClauseNode;
Expand Down Expand Up @@ -51,13 +52,16 @@
import org.ballerinalang.model.tree.TupleVariableNode;
import org.ballerinalang.model.tree.TypeDefinition;
import org.ballerinalang.model.tree.XMLNSDeclarationNode;
import org.ballerinalang.model.tree.bindingpattern.CaptureBindingPattern;
import org.ballerinalang.model.tree.bindingpattern.ListBindingPattern;
import org.ballerinalang.model.tree.expressions.AnnotAccessNode;
import org.ballerinalang.model.tree.expressions.ArrowFunctionNode;
import org.ballerinalang.model.tree.expressions.BinaryExpressionNode;
import org.ballerinalang.model.tree.expressions.CheckPanickedExpressionNode;
import org.ballerinalang.model.tree.expressions.CheckedExpressionNode;
import org.ballerinalang.model.tree.expressions.ElvisExpressionNode;
import org.ballerinalang.model.tree.expressions.ErrorVariableReferenceNode;
import org.ballerinalang.model.tree.expressions.ExpressionNode;
import org.ballerinalang.model.tree.expressions.FieldBasedAccessNode;
import org.ballerinalang.model.tree.expressions.GroupExpressionNode;
import org.ballerinalang.model.tree.expressions.IndexBasedAccessNode;
Expand Down Expand Up @@ -102,6 +106,9 @@
import org.ballerinalang.model.tree.expressions.XMLQNameNode;
import org.ballerinalang.model.tree.expressions.XMLQuotedStringNode;
import org.ballerinalang.model.tree.expressions.XMLTextLiteralNode;
import org.ballerinalang.model.tree.matchpatterns.ConstPatternNode;
import org.ballerinalang.model.tree.matchpatterns.VarBindingPatternMatchPatternNode;
import org.ballerinalang.model.tree.matchpatterns.WildCardMatchPatternNode;
import org.ballerinalang.model.tree.statements.AssignmentNode;
import org.ballerinalang.model.tree.statements.BlockStatementNode;
import org.ballerinalang.model.tree.statements.BreakNode;
Expand All @@ -121,6 +128,7 @@
import org.ballerinalang.model.tree.statements.MatchNode.MatchStaticBindingPatternNode;
import org.ballerinalang.model.tree.statements.MatchNode.MatchStructuredBindingPatternNode;
import org.ballerinalang.model.tree.statements.MatchNode.MatchTypedBindingPatternNode;
import org.ballerinalang.model.tree.statements.MatchStatementNode;
import org.ballerinalang.model.tree.statements.PanicNode;
import org.ballerinalang.model.tree.statements.QueryActionNode;
import org.ballerinalang.model.tree.statements.RecordDestructureNode;
Expand Down Expand Up @@ -175,11 +183,14 @@
import org.wso2.ballerinalang.compiler.tree.BLangTupleVariable;
import org.wso2.ballerinalang.compiler.tree.BLangTypeDefinition;
import org.wso2.ballerinalang.compiler.tree.BLangXMLNS;
import org.wso2.ballerinalang.compiler.tree.bindingpatterns.BLangCaptureBindingPattern;
import org.wso2.ballerinalang.compiler.tree.bindingpatterns.BLangListBindingPattern;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangDoClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangFromClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangJoinClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangLetClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangLimitClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangMatchClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnConflictClause;
import org.wso2.ballerinalang.compiler.tree.clauses.BLangOnFailClause;
Expand Down Expand Up @@ -214,6 +225,7 @@
import org.wso2.ballerinalang.compiler.tree.expressions.BLangMarkdownReturnParameterDocumentation;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangMatchExpression;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangMatchExpression.BLangMatchExprPatternClause;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangMatchGuard;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangNumericLiteral;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangObjectConstructorExpression;
Expand Down Expand Up @@ -251,6 +263,9 @@
import org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString;
import org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLTextLiteral;
import org.wso2.ballerinalang.compiler.tree.matchpatterns.BLangConstPattern;
import org.wso2.ballerinalang.compiler.tree.matchpatterns.BLangVarBindingPatternMatchPattern;
import org.wso2.ballerinalang.compiler.tree.matchpatterns.BLangWildCardMatchPattern;
import org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment;
import org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt;
import org.wso2.ballerinalang.compiler.tree.statements.BLangBreak;
Expand All @@ -270,6 +285,7 @@
import org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStaticBindingPatternClause;
import org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStructuredBindingPatternClause;
import org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchTypedBindingPatternClause;
import org.wso2.ballerinalang.compiler.tree.statements.BLangMatchStatement;
import org.wso2.ballerinalang.compiler.tree.statements.BLangPanic;
import org.wso2.ballerinalang.compiler.tree.statements.BLangRecordDestructure;
import org.wso2.ballerinalang.compiler.tree.statements.BLangRecordVariableDef;
Expand Down Expand Up @@ -731,6 +747,38 @@ public static MatchNode createMatchStatement() {
return new BLangMatch();
}

public static MatchStatementNode createMatchStatementNode() {
return new BLangMatchStatement();
}

public static WildCardMatchPatternNode createWildCardMatchPattern() {
return new BLangWildCardMatchPattern();
}

public static ConstPatternNode createConstMatchPattern() {
return new BLangConstPattern();
}

public static VarBindingPatternMatchPatternNode createVarBindingPattern() {
return new BLangVarBindingPatternMatchPattern();
}

public static MatchClauseNode createMatchClause() {
return new BLangMatchClause();
}

public static ExpressionNode createMatchGuard() {
return new BLangMatchGuard();
}

public static CaptureBindingPattern createCaptureBindingPattern() {
return new BLangCaptureBindingPattern();
}

public static ListBindingPattern createListBindingPattern() {
return new BLangListBindingPattern();
}

public static MatchTypedBindingPatternNode createMatchStatementSimpleBindingPattern() {
return new BLangMatchTypedBindingPatternClause();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.clauses;

import org.ballerinalang.model.tree.Node;
import org.ballerinalang.model.tree.expressions.ExpressionNode;
import org.ballerinalang.model.tree.expressions.MatchGuard;
import org.ballerinalang.model.tree.matchpatterns.MatchPatternNode;
import org.ballerinalang.model.tree.statements.BlockStatementNode;

import java.util.List;

/**
* The interface with the APIs to implement the match-clause.
*
* @since Swan Lake
*/
public interface MatchClauseNode extends Node {

MatchGuard getMatchGuard();

void setMatchGuard(MatchGuard matchGuard);

BlockStatementNode getBLockStatement();

void setBlockStatement(BlockStatementNode blockStatement);

List<? extends MatchPatternNode> getMatchPatterns();

void addMatchPattern(MatchPatternNode matchPattern);

boolean isLastClause();

void setLastClause();

ExpressionNode getExpression();

void setExpression(ExpressionNode expression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public enum NodeKind {
FORK_JOIN,
IF,
MATCH,
MATCH_STATEMENT,
MATCH_TYPED_PATTERN_CLAUSE,
MATCH_STATIC_PATTERN_CLAUSE,
MATCH_STRUCTURED_PATTERN_CLAUSE,
Expand Down Expand Up @@ -188,6 +189,16 @@ public enum NodeKind {
ORDER_BY,
ORDER_KEY,
ON_FAIL,
MATCH_CLAUSE,

/* Match patterns */
CONST_MATCH_PATTERN,
WILDCARD_MATCH_PATTERN,
VAR_BINDING_PATTERN_MATCH_PATTERN,

/* Binding patterns*/
CAPTURE_BINDING_PATTERN,
LIST_BINDING_PATTERN,

/* Types */
ARRAY_TYPE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.tree.bindingpattern;

import org.ballerinalang.model.tree.Node;

/**
* The interface with the APIs to implement the binding-pattern.
*
* @since Swan Lake
*/
public interface BindingPatternNode extends Node {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.tree.bindingpattern;

import org.ballerinalang.model.symbols.VariableSymbol;
import org.ballerinalang.model.tree.IdentifierNode;
import org.ballerinalang.model.tree.Node;

/**
* The interface with the APIs to implement the capture-binding-pattern.
*
* @since Swan Lake
*/
public interface CaptureBindingPattern extends Node {

IdentifierNode getIdentifier();

void setIdentifier(IdentifierNode variableName);

VariableSymbol getSymbol();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.tree.bindingpattern;

import org.ballerinalang.model.tree.Node;

import java.util.List;

/**
* The interface with the APIs to implement the list-binding-pattern.
*
* @since Swan Lake
*/
public interface ListBindingPattern extends Node {
List<? extends BindingPatternNode> getBindingPatterns();

void addBindingPattern(BindingPatternNode bindingPattern);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.tree.expressions;

/**
* The interface with the APIs to implement the match-guard.
*
* @since Swan Lake
*/
public interface MatchGuard {
ExpressionNode getExpression();

void setExpression(ExpressionNode expression);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.ballerinalang.model.tree.matchpatterns;

import org.ballerinalang.model.tree.Node;
import org.ballerinalang.model.tree.expressions.ExpressionNode;

/**
* The interface with the APIs to implement the const-pattern.
*
* @since Swan Lake
*/
public interface ConstPatternNode extends Node {

ExpressionNode getExpresion();

void setExpression(ExpressionNode expression);
}
Loading