Skip to content

Commit

Permalink
hopefully fixed now
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Oct 28, 2024
1 parent 7ed010b commit f84d6b9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/taumc/glsl/ReplaceExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.taumc.glsl.grammar.GLSLLexer;
import org.taumc.glsl.grammar.GLSLParser;
import org.taumc.glsl.grammar.GLSLParserBaseListener;
Expand Down Expand Up @@ -32,16 +33,23 @@ public void enterBinary_expression(GLSLParser.Binary_expressionContext ctx) {
if (ctx.unary_expression() != null) {
if (ctx.unary_expression().postfix_expression() != null) {
if (ctx.unary_expression().postfix_expression().postfix_expression() != null) {
if (ctx.unary_expression().postfix_expression().postfix_expression().getText().equals(oldExpression.getText())) {
var postfix = ctx.unary_expression().postfix_expression().postfix_expression();
while (postfix.getText().startsWith(oldExpression.getText()) && !postfix.getText().equals(oldExpression.getText())) {
if (postfix.postfix_expression() != null) {
postfix = postfix.postfix_expression();
} else {
break;
}
}
if (postfix.getText().equals(oldExpression.getText())) {
GLSLLexer lexer = new GLSLLexer(CharStreams.fromString(newExpression));
GLSLParser parser = new GLSLParser(new CommonTokenStream(lexer));
var expr = parser.postfix_expression();
expr.parent = ctx.unary_expression().postfix_expression();
int i = ctx.unary_expression().postfix_expression().children.indexOf(ctx.unary_expression().postfix_expression().postfix_expression());
ctx.unary_expression().postfix_expression().children.set(i, expr);
expr.parent = postfix.getParent();
int i = postfix.getParent().children.indexOf(postfix);
postfix.getParent().children.set(i, expr);
}
}

}
}
}
Expand Down

0 comments on commit f84d6b9

Please sign in to comment.