<commit_before>﻿/*----------------------------------------------------------
This Source Code Form is subject to the terms of the 
Mozilla Public License, v.2.0. If a copy of the MPL 
was not distributed with this file, You can obtain one 
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using System;

namespace OneScript.Language.LexicalAnalysis
{
    public class PreprocessorDirectiveLexerState : LexerState
    {
        WordLexerState _wordExtractor = new WordLexerState();

        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            System.Diagnostics.Debug.Assert(iterator.CurrentSymbol == SpecialChars.Preprocessor);

            if (!iterator.OnNewLine)
                throw CreateExceptionOnCurrentLine("Недопустимое начало директивы препроцессора", iterator);

            iterator.MoveNext();
            if (!iterator.MoveToContent())
                throw CreateExceptionOnCurrentLine("Ожидается директива", iterator);
            
            if (!Char.IsLetter(iterator.CurrentSymbol))
                throw CreateExceptionOnCurrentLine("Ожидается директива препроцессора", iterator);
            
            var lex = _wordExtractor.ReadNextLexem(iterator);

            lex.Type = LexemType.PreprocessorDirective;

            return lex;

        }
    }
}<commit_msg>указывать на ошибку в строке с '#', если имя директивы ниже<commit_after>﻿/*----------------------------------------------------------
This Source Code Form is subject to the terms of the 
Mozilla Public License, v.2.0. If a copy of the MPL 
was not distributed with this file, You can obtain one 
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using System;

namespace OneScript.Language.LexicalAnalysis
{
    public class PreprocessorDirectiveLexerState : LexerState
    {
        WordLexerState _wordExtractor = new WordLexerState();

        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            System.Diagnostics.Debug.Assert(iterator.CurrentSymbol == SpecialChars.Preprocessor);

            if (!iterator.OnNewLine)
                throw CreateExceptionOnCurrentLine("Недопустимое начало директивы препроцессора", iterator);

            iterator.MoveNext();
            var position = iterator.GetPositionInfo();
            if (!iterator.MoveToContent())
                throw CreateExceptionOnCurrentLine("Ожидается директива препроцессора", iterator);
            if (position.LineNumber != iterator.CurrentLine)
                throw new SyntaxErrorException(position, "Ожидается директива препроцессора");

            if (!Char.IsLetter(iterator.CurrentSymbol))
                throw CreateExceptionOnCurrentLine("Ожидается директива препроцессора", iterator);
            
            var lex = _wordExtractor.ReadNextLexem(iterator);

            lex.Type = LexemType.PreprocessorDirective;

            return lex;
        }
    }
}
{'fraction_non_alphanumeric': 0.14890073284477015, 'fraction_numerical': 0.002664890073284477, 'mean_word_length': 2.0642857142857145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6441997', 'n_tokens_mistral': 791, 'n_tokens_neox': 784, 'n_words': 186}