@@ -13,7 +13,7 @@ namespace OneScript.Language.LexicalAnalysis
1313 public class PreprocessingLexer : ILexemGenerator
1414 {
1515 HashSet < string > _definitions = new HashSet < string > ( StringComparer . InvariantCultureIgnoreCase ) ;
16- ILexemGenerator _lexer ;
16+ FullSourceLexer _lexer ;
1717 string _code ;
1818
1919 Lexem _lastExtractedLexem ;
@@ -333,14 +333,34 @@ private void CheckNewLine()
333333 throw PreprocessorError ( "Недопустимые символы в директиве" ) ;
334334 }
335335
336+ private void SkipComment ( )
337+ {
338+ _lexer . Iterator . MoveToContent ( ) ;
339+ if ( ! _lexer . Iterator . OnNewLine )
340+ {
341+ MoveNext ( ) ;
342+ if ( _lastExtractedLexem . Type != LexemType . Comment )
343+ throw PreprocessorError ( "Недопустимые символы в директиве" ) ;
344+ }
345+ }
346+
347+ private void SkipErrors ( object sender , LexerErrorEventArgs args )
348+ {
349+ args . Iterator . MoveNext ( ) ;
350+ args . IsHandled = true ;
351+ }
352+
336353 private void SkipTillNextDirective ( )
337354 {
338- int currentLevel = BlockLevel ( ) ;
339- MoveNext ( ) ;
340- CheckNewLine ( ) ;
355+ SkipComment ( ) ;
356+
357+ _lexer . UnexpectedCharacterFound += SkipErrors ;
341358
359+ int currentLevel = BlockLevel ( ) ;
342360 while ( true )
343361 {
362+ MoveNext ( ) ;
363+
344364 while ( _lastExtractedLexem . Type != LexemType . PreprocessorDirective )
345365 {
346366 if ( _lastExtractedLexem . Token == Token . EndOfText )
@@ -351,13 +371,16 @@ private void SkipTillNextDirective()
351371
352372 if ( _lastExtractedLexem . Token == Token . If )
353373 PushBlock ( ) ;
354- else if ( _lastExtractedLexem . Token == Token . EndIf && BlockLevel ( ) > currentLevel )
355- PopBlock ( ) ;
356- else if ( BlockLevel ( ) == currentLevel )
357- break ;
358-
359- MoveNext ( ) ;
374+ else if ( _lastExtractedLexem . Token == Token . EndIf )
375+ {
376+ if ( BlockLevel ( ) > currentLevel )
377+ PopBlock ( ) ;
378+ else if ( BlockLevel ( ) == currentLevel )
379+ break ;
380+ }
360381 }
382+
383+ _lexer . UnexpectedCharacterFound -= SkipErrors ;
361384 }
362385 }
363386}
0 commit comments