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

trying to work on issue #101 #1900

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading