Skip to content

Commit

Permalink
trying to work on issue 101
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Dec 21, 2023
1 parent ce8e98d commit 5c251b7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/org/rascalmpl/interpreter/matching/RegExpPatternValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.rascalmpl.interpreter.IEvaluatorContext;
import org.rascalmpl.interpreter.env.Environment;
import org.rascalmpl.interpreter.result.Result;
import org.rascalmpl.interpreter.result.ResultFactory;
import org.rascalmpl.interpreter.staticErrors.RedeclaredVariable;
import org.rascalmpl.interpreter.staticErrors.SyntaxError;
import org.rascalmpl.semantics.dynamic.RegExpLiteral;
Expand Down Expand Up @@ -88,7 +89,7 @@ public void initMatch(Result<IValue> subject) {

Type runType = subject.getValue().getType();

if(runType.isSubtypeOf(tf.stringType())) {
if (runType.isSubtypeOf(tf.stringType())) {
this.subject = ((IString) subject.getValue()).getValue();
}
else {
Expand All @@ -100,8 +101,15 @@ public void initMatch(Result<IValue> subject) {

try {
String RegExpAsString = interpolate(ctx);
pat = Pattern.compile(RegExpAsString, Pattern.UNICODE_CHARACTER_CLASS);
} catch (PatternSyntaxException e){
this.pat = Pattern.compile(RegExpAsString, Pattern.UNICODE_CHARACTER_CLASS);
matcher = this.pat.matcher(((IString) subject.getValue()).getValue());
IString empty = ctx.getValueFactory().string("");

// Initialize all pattern variables to ""
for (String name : patternVars) {
ctx.getCurrentEnvt().declareAndStoreInferredInnerScopeVariable(name, ResultFactory.makeResult(tf.stringType(), empty, ctx));
}
} catch (PatternSyntaxException e) {
throw new SyntaxError(e.getMessage(), ctx.getCurrentAST().getLocation());
}
}
Expand Down Expand Up @@ -145,17 +153,6 @@ private boolean findMatch(){
public boolean next(){
if (firstMatch){
firstMatch = false;
matcher = pat.matcher(subject);
IString empty = ctx.getValueFactory().string("");

// Initialize all pattern variables to ""
for(String name : patternVars){
if(!this.iWroteItMySelf && !ctx.getCurrentEnvt().declareVariable(tf.stringType(), name)) {
throw new RedeclaredVariable(name, ctx.getCurrentAST());
}
ctx.getCurrentEnvt().storeVariable(name, makeResult(tf.stringType(), empty, ctx));
}
this.iWroteItMySelf = true;
}

try {
Expand Down

0 comments on commit 5c251b7

Please sign in to comment.