Skip to content

Commit

Permalink
GH-518 Due to random bugs and unexpected behaviours, sort subparsers …
Browse files Browse the repository at this point in the history
…in alphabetical order
  • Loading branch information
dzikoysk committed May 25, 2020
1 parent ed3b6ee commit 61d009e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface ExpressionSubparser extends Parser, Comparable<ExpressionSubpar
* Creates worker of the current subparser
*
* @return the worker instance
* @param context
* @param context the context to use by the worker
*/
ExpressionSubparserWorker createWorker(Context context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public PandaExpressionSubparserRepresentation(ExpressionSubparser subparser) {

@Override
public int compareTo(@NotNull PandaExpressionSubparserRepresentation to) {
int result = subparser.compareTo(to.getSubparser());
return result == 0 ? Integer.compare(usages, to.getUsages()) : result;
int byPriority = subparser.compareTo(to.getSubparser());
return byPriority == 0 ? subparser.getSubparserName().compareTo(to.subparser.getSubparserName()) : byPriority;
}

public void increaseUsages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.StaticExpressionSubparser;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.VariableExpressionSubparser;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.assignation.AssignationExpressionSubparser;
import org.panda_lang.utilities.commons.collection.Sets;

import java.util.Arrays;
import java.util.Collection;

public final class PandaExpressions {
Expand All @@ -45,8 +45,8 @@ public final class PandaExpressions {
* Array of default expression subparsers
*/
public static final ExpressionSubparser[] SUBPARSERS = {
new ArrayValueExpressionSubparser(),
new AssignationExpressionSubparser(),
new ArrayValueExpressionSubparser(),
new CastExpressionSubparser(),
new ConstructorExpressionSubparser(),
new CreaseExpressionSubparser(),
Expand All @@ -64,7 +64,7 @@ public final class PandaExpressions {
};

public static Collection<ExpressionSubparser> getSubparsers() {
return Arrays.asList(SUBPARSERS);
return Sets.newHashSet(SUBPARSERS);
}

public static ExpressionSubparsers getExpressionSubparsers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import org.panda_lang.framework.design.interpreter.token.Snippetable;
import org.panda_lang.framework.design.interpreter.token.TokenInfo;
import org.panda_lang.framework.language.resource.syntax.TokenTypes;
import org.panda_lang.framework.language.resource.syntax.operator.Operator;
import org.panda_lang.framework.language.resource.syntax.operator.OperatorFamilies;
import org.panda_lang.framework.language.resource.syntax.operator.OperatorUtils;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.operation.Operation;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.operation.Operation.OperationElement;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.operation.OperationParser;
Expand Down Expand Up @@ -83,6 +86,12 @@ private static final class OperationWorker extends AbstractExpressionSubparserWo
return null;
}

Operator operator = token.toToken();

if (OperatorUtils.isMemberOf(operator, OperatorFamilies.ASSIGNATION)) {
return null;
}

if (elements == null) {
this.elements = new ArrayList<>(3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public int getMinimalRequiredLengthOfSource() {
return 3;
}

@Override
public double getPriority() {
return -1;
}

@Override
public ExpressionCategory getCategory() {
return ExpressionCategory.STANDALONE;
Expand Down

0 comments on commit 61d009e

Please sign in to comment.