<commit_before>class Parser {
    private expr: string;
    private env;
    error;
    result;

    constructor (str: string, env) {
        this.expr = str;
        this.env = env;
    }

    parseCondition() {
        var ast = JSON.parse(JSON.stringify(luaparse.parse("x = " + this.expr)));
        var node = ast.body[0].init[0];
        this.result = this.calc(node);
    }

    calc(node)
    {
        if (node.type == "BinaryExpression")
        {
            if (node.left != null && node.right != null)
            {
                switch (node.operator)
                {
                    case "+":
                        return this.calc(node.left) + this.calc(node.right);
                        break;
                    case "-":
                        return this.calc(node.left) - this.calc(node.right);
                        break;
                    case "*":
                        return this.calc(node.left) * this.calc(node.right);
                        break;
                    case "/":
                        return this.calc(node.left) / this.calc(node.right);
                        break;
                    case ">":
                        return this.calc(node.left) > this.calc(node.right);
                        break;
                    case "<":
                        return this.calc(node.left) < this.calc(node.right);
                        break;
                    //TODO tableconstructor, tableindexing, functioncalls, concatenation, twodtable
                    //TODO ^,>=,<=,==,or,and,&&,||,not
                }
            }
        }

        if (node.type == "Identifier")
        {
            var variablesMap = InterpretManager.getVariablesMap();
            if (variablesMap[node.name] == null) {
                this.error = "No such variable:" + node.name;
                return 0;
            }
            return variablesMap[node.name];
        }

        if (node.type == "NumericLiteral")
        {
            return node.value;
        }

        this.error = "error";
    }
}<commit_msg>Improved brand new parser!<commit_after>class Parser {
    private expr: string;
    private env;
    error;
    result;

    constructor (str: string, env) {
        this.expr = str;
        this.env = env;
    }

    parseCondition() {
        var ast = JSON.parse(JSON.stringify(luaparse.parse("x = " + this.expr)));
        var node = ast.body[0].init[0];
        this.result = this.calc(node);
    }

    calc(node)
    {
        if (node.type == "BinaryExpression")
        {
            if (node.left != null && node.right != null)
            {
                switch (node.operator)
                {
                    case "+":
                        return this.calc(node.left) + this.calc(node.right);
                        break;
                    case "-":
                        return this.calc(node.left) - this.calc(node.right);
                        break;
                    case "*":
                        return this.calc(node.left) * this.calc(node.right);
                        break;
                    case "/":
                        return this.calc(node.left) / this.calc(node.right);
                        break;
                    case "^":
                        return this.calc(node.left) ^ this.calc(node.right);
                        break;
                    case ">":
                        return this.calc(node.left) > this.calc(node.right);
                        break;
                    case "<":
                        return this.calc(node.left) < this.calc(node.right);
                        break;
                    case ">=":
                        return this.calc(node.left) >= this.calc(node.right);
                        break;
                    case "<=":
                        return this.calc(node.left) <= this.calc(node.right);
                        break;
                    case "==":
                        return this.calc(node.left) == this.calc(node.right);
                        break;
                    case "or":
                    case "||":
                        return this.calc(node.left) || this.calc(node.right);
                        break;
                    case "and":
                    case "&&":
                        return this.calc(node.left) && this.calc(node.right);
                        break;
                    case "<":
                        return this.calc(node.left) < this.calc(node.right);
                        break;
                    //TODO tableconstructor, tableindexing, functioncalls, concatenation, twodtable
                }
            }
        }

        if (node.type == "Identifier")
        {
            var variablesMap = InterpretManager.getVariablesMap();
            if (variablesMap[node.name] == null) {
                this.error = "No such variable:" + node.name;
                return 0;
            }
            return variablesMap[node.name];
        }

        if (node.type == "NumericLiteral")
        {
            return node.value;
        }

        this.error = "Unresolved input";
    }
}
{'fraction_non_alphanumeric': 0.11827332559039876, 'fraction_numerical': 0.0011614401858304297, 'mean_word_length': 1.004266873545384, 'pattern_counts': {'":': 21, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5935292', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1254, 'n_words': 243}