<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Antlr4;
using Antlr4.Runtime;

namespace Rubberduck.Math
{
    public static class Calculator
    {
        public static int Evaluate(string expression)
        {
            var lexer = new BasicMathLexer(new AntlrInputStream(expression));
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new ThrowExceptionErrorListener());

            var tokens = new CommonTokenStream(lexer);
            var parser = new BasicMathParser(tokens);

            var tree = parser.compileUnit();

            var visitor = new IntegerMathVisitor();

            return visitor.Visit(tree);
        }
    }
}
<commit_msg>Throw exception if more than one expression is passed to Evaluate<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Antlr4;
using Antlr4.Runtime;

namespace Rubberduck.Math
{
    public static class Calculator
    {
        public static int Evaluate(string expression)
        {
            var lexer = new BasicMathLexer(new AntlrInputStream(expression));
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new ThrowExceptionErrorListener());

            var tokens = new CommonTokenStream(lexer);
            var parser = new BasicMathParser(tokens);

            var tree = parser.compileUnit();

            var exprCount = tree.expression().Count;
            if (exprCount > 1)
            {
                throw new ArgumentException(String.Format("Too many expressions. Only one can be evaluated. {0} expressions were entered.", exprCount));
            }

            var visitor = new IntegerMathVisitor();

            return visitor.Visit(tree);
        }
    }
}

{'fraction_non_alphanumeric': 0.08208154506437768, 'fraction_numerical': 0.003218884120171674, 'mean_word_length': 2.538899430740038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '203955', 'n_tokens_mistral': 483, 'n_tokens_neox': 465, 'n_words': 131}