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

added implementation of negative number matching. #1914

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 10 additions & 2 deletions src/org/rascalmpl/interpreter/matching/NegativePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.rascalmpl.interpreter.IEvaluatorContext;
import org.rascalmpl.interpreter.env.Environment;
import org.rascalmpl.interpreter.result.Result;
import org.rascalmpl.values.IRascalValueFactory;

import io.usethesource.vallang.IValue;
import io.usethesource.vallang.INumber;
import io.usethesource.vallang.type.Type;

public class NegativePattern extends AbstractMatchingResult {
Expand All @@ -43,7 +46,7 @@

@Override
public boolean mayMatch(Type subjectType, Environment env){
return pat.mayMatch(subjectType, env);
return subjectType.isSubtypeOf(tf.numberType()) && pat.mayMatch(subjectType, env);
}

@Override
Expand All @@ -53,6 +56,11 @@

@Override
public boolean next() {
return pat.next();
if (pat.next()) {
if (subject.getDynamicType().isNumber()) {
return ((INumber) subject.getValue()).lessEqual(IRascalValueFactory.getInstance().integer(0)).getValue();

Check warning on line 61 in src/org/rascalmpl/interpreter/matching/NegativePattern.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/interpreter/matching/NegativePattern.java#L61

Added line #L61 was not covered by tests
}
}
return false;

Check warning on line 64 in src/org/rascalmpl/interpreter/matching/NegativePattern.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/interpreter/matching/NegativePattern.java#L64

Added line #L64 was not covered by tests
}
}
9 changes: 8 additions & 1 deletion src/org/rascalmpl/semantics/dynamic/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -1918,8 +1918,15 @@
}

@Override
@SuppressWarnings("unchecked")
public IMatchingResult buildMatcher(IEvaluatorContext __eval, boolean bindTypeParameters) {
return new NegativePattern(__eval, this, getArgument().buildMatcher(__eval, bindTypeParameters));
Type t = getArgument().typeOf(__eval.getCurrentEnvt(), (IEvaluator<Result<IValue>>) __eval, bindTypeParameters);

Check warning on line 1923 in src/org/rascalmpl/semantics/dynamic/Expression.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Expression.java#L1923

Added line #L1923 was not covered by tests

if (getArgument().isTypedVariable() || getArgument().isQualifiedName() || getArgument().isLiteral()) {
return new NegativePattern(__eval, this, getArgument().buildMatcher(__eval, bindTypeParameters));

Check warning on line 1926 in src/org/rascalmpl/semantics/dynamic/Expression.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Expression.java#L1926

Added line #L1926 was not covered by tests
}

throw new UnexpectedType(TF.numberType(), t, getLocation());

Check warning on line 1929 in src/org/rascalmpl/semantics/dynamic/Expression.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Expression.java#L1929

Added line #L1929 was not covered by tests
}

@Override
Expand Down
Loading