<commit_before>﻿using System;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;

namespace Lakewood.AutoScaleFormulaLanguageService
{
    internal class AutoScaleFormulaScanner : IScanner
    {
        private readonly IVsTextLines _buffer;
        private string _source;
        private int _index;

        public AutoScaleFormulaScanner(IVsTextLines buffer)
        {
            _buffer = buffer;
        }

        bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
        {
            if (_index >= _source.Length)
            {
                return false;
            }

            char ch = _source[_index];
            tokenInfo.StartIndex = _index;

            if (char.IsWhiteSpace(ch))
            {
                tokenInfo.Type = TokenType.WhiteSpace;
                tokenInfo.Color = TokenColor.Text;

                char? chPeek;
                while ((chPeek = Peek()).HasValue && char.IsWhiteSpace(chPeek.Value))
                {
                    ++_index;
                }
            }
            else if (ch == '(' || ch == ')' || ch == ';' || ch == ',')
            {
                tokenInfo.Type = TokenType.Delimiter;
                tokenInfo.Color = TokenColor.Text;
            }
            else if (ch == '+' || ch == '-' || ch == '/' || ch == '*' || ch == '?' || ch == ':')
            {
                tokenInfo.Type = TokenType.Operator;
                tokenInfo.Color = TokenColor.Number;
            }
            else if (ch == '<' || ch == '>' || ch == '!')<commit_msg>Refactor: group related initial characters into strings<commit_after>﻿using System.Linq;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;

namespace Lakewood.AutoScaleFormulaLanguageService
{
    internal class AutoScaleFormulaScanner : IScanner
    {
        private static readonly char[] s_delimiters = "();,".ToCharArray();
        private static readonly char[] s_singleCharacterOperators = "+-/*?:".ToCharArray();
        private static readonly char[] s_operatorsWithOptionalEquals = "<>!".ToCharArray();

        private readonly IVsTextLines _buffer;
        private string _source;
        private int _index;

        public AutoScaleFormulaScanner(IVsTextLines buffer)
        {
            _buffer = buffer;
        }

        bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
        {
            if (_index >= _source.Length)
            {
                return false;
            }

            char ch = _source[_index];
            tokenInfo.StartIndex = _index;

            if (char.IsWhiteSpace(ch))
            {
                tokenInfo.Type = TokenType.WhiteSpace;
                tokenInfo.Color = TokenColor.Text;

                char? chPeek;
                while ((chPeek = Peek()).HasValue && char.IsWhiteSpace(chPeek.Value))
                {
                    ++_index;
                }
            }
            else if (s_delimiters.Contains(ch))
            {
                tokenInfo.Type = TokenType.Delimiter;
                tokenInfo.Color = TokenColor.Text;
            }
            else if (s_singleCharacterOperators.Contains(ch))
            {
                tokenInfo.Type = TokenType.Operator;
                tokenInfo.Color = TokenColor.Number;
            }
            else if (s_operatorsWithOptionalEquals.Contains(ch))
{'fraction_non_alphanumeric': 0.10159651669085631, 'fraction_numerical': 0.0, 'mean_word_length': 1.6671826625386996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7147917', 'n_tokens_mistral': 926, 'n_tokens_neox': 887, 'n_words': 180}