<commit_before>package me.cvhc.equationsolver;

import org.antlr.v4.runtime.ANTLRErrorListener;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeProperty;

import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class ExpressionEvaluator {
    public static class PropertyStruct {
        public HashSet<Character> Variables = new HashSet<>();
        public double Value = Double.NaN;
        public boolean Determined = false;
    }

    private ExpressionVisitorImpl Evaluator;
    private ParseTree ASTree;
    private boolean ErrorFlag = false;
    private PropertyStruct Property;

    private HashMap<Character, Double> VariableList = new HashMap<>();
    private HashSet<Character> CachedVariables = new HashSet<>();

    public ExpressionEvaluator(String exp) {
        ExpressionLexer lexer = new ExpressionLexer(new ANTLRInputStream(exp));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        ExpressionParser parser = new ExpressionParser(tokens);

        parser.removeErrorListeners();
        parser.addErrorListener(new BaseErrorListener() {
            @Override
            public void syntaxError(Recognizer<?, ?> recognizer,
                                    Object offendingSymbol,
                                    int line, int charPositionInLine,
                                    String msg,
                                    RecognitionException e) {
                ErrorFlag = true;
            }
        });

        ASTree = parser.expr();
        if (!ErrorFlag) {
            Evaluator = new ExpressionVisitorImpl();
            Property = Evaluator.visit(ASTree);
        }
    }

    public boolean isError() {
        return ErrorFlag;
    }

    public PropertyStruct getProperty() {
        return Property;
    }

    public Double getValue() {
        return Property.Determined ? Property.Value : null;
    }<commit_msg>ExpressionEvaluator: save original expression<commit_after>package me.cvhc.equationsolver;

import org.antlr.v4.runtime.ANTLRErrorListener;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeProperty;

import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class ExpressionEvaluator {
    public static class PropertyStruct {
        public HashSet<Character> Variables = new HashSet<>();
        public double Value = Double.NaN;
        public boolean Determined = false;
    }

    private String Expression;
    private ExpressionVisitorImpl Evaluator;
    private ParseTree ASTree;
    private boolean ErrorFlag = false;
    private PropertyStruct Property;

    private HashMap<Character, Double> VariableList = new HashMap<>();
    private HashSet<Character> CachedVariables = new HashSet<>();

    public ExpressionEvaluator(String exp) {
        ExpressionLexer lexer = new ExpressionLexer(new ANTLRInputStream(exp));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        ExpressionParser parser = new ExpressionParser(tokens);
        Expression = new String(exp);

        parser.removeErrorListeners();
        parser.addErrorListener(new BaseErrorListener() {
            @Override
            public void syntaxError(Recognizer<?, ?> recognizer,
                                    Object offendingSymbol,
                                    int line, int charPositionInLine,
                                    String msg,
                                    RecognitionException e) {
                ErrorFlag = true;
            }
        });

        ASTree = parser.expr();
        if (!ErrorFlag) {
            Evaluator = new ExpressionVisitorImpl();
            Property = Evaluator.visit(ASTree);
        }
    }

    @Override
    public String toString() {
        return Expression;
    }

    public boolean isError() {
        return ErrorFlag;
    }

    public PropertyStruct getProperty() {
        return Property;
    }

    public Double getValue() {
        return Property.Determined ? Property.Value : null;
    }
{'fraction_non_alphanumeric': 0.08530020703933748, 'fraction_numerical': 0.004554865424430642, 'mean_word_length': 2.573224852071006, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6815977', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1265, 'n_words': 291}