@@ -49,20 +49,20 @@ public DefaultBslParser(
4949
5050 private IErrorSink ErrorSink { get ; }
5151
52- public IEnumerable < CodeError > Errors => ErrorSink . Errors ?? new CodeError [ 0 ] ;
52+ public IEnumerable < CodeError > Errors => ErrorSink . Errors ?? Array . Empty < CodeError > ( ) ;
5353
5454 public BslSyntaxNode ParseStatefulModule ( )
5555 {
5656 ModuleNode node ;
5757
5858 _preprocessorHandlers . OnModuleEnter ( ) ;
59- NextLexem ( ) ;
60-
59+ NextLexem ( ) ;
60+
61+ node = new ModuleNode ( _lexer . Iterator . Source , _lastExtractedLexem ) ;
62+ PushContext ( node ) ;
6163 try
6264 {
63- node = new ModuleNode ( _lexer . Iterator . Source , _lastExtractedLexem ) ;
64- PushContext ( node ) ;
65- ParseModuleSections ( ) ;
65+ ParseModuleSections ( ) ;
6666 }
6767 finally
6868 {
@@ -81,11 +81,9 @@ public BslSyntaxNode ParseCodeBatch(bool allowReturns = false)
8181 PushContext ( node ) ;
8282 try
8383 {
84- if ( allowReturns )
85- {
86- _inMethodScope = true ;
87- _isInFunctionScope = true ;
88- }
84+ _inMethodScope = allowReturns ;
85+ _isInFunctionScope = allowReturns ;
86+
8987 BuildModuleBody ( ) ;
9088 }
9189 finally
@@ -180,20 +178,16 @@ private void BuildVariableSection()
180178 while ( true )
181179 {
182180 BuildAnnotations ( ) ;
183- if ( _lastExtractedLexem . Token == Token . VarDef )
184- {
185- if ( ! hasVars )
186- {
187- hasVars = true ;
188- parent . AddChild ( allVarsSection ) ;
189- }
190-
191- BuildVariableDefinition ( ) ;
192- }
193- else
194- {
195- break ;
196- }
181+ if ( _lastExtractedLexem . Token != Token . VarDef )
182+ break ;
183+
184+ if ( ! hasVars )
185+ {
186+ hasVars = true ;
187+ parent . AddChild ( allVarsSection ) ;
188+ }
189+
190+ BuildVariableDefinition ( ) ;
197191 }
198192 }
199193 finally
@@ -296,21 +290,17 @@ private void BuildMethodsSection()
296290 while ( true )
297291 {
298292 BuildAnnotations ( ) ;
299- if ( IsStartOfMethod ( _lastExtractedLexem ) )
300- {
301- if ( ! sectionExist )
302- {
303- sectionExist = true ;
304- _isMethodsDefined = true ;
305- parent . AddChild ( allMethodsSection ) ;
306- }
307-
308- BuildMethod ( ) ;
309- }
310- else
311- {
312- break ;
313- }
293+ if ( ! IsStartOfMethod ( _lastExtractedLexem ) )
294+ break ;
295+
296+ if ( ! sectionExist )
297+ {
298+ sectionExist = true ;
299+ _isMethodsDefined = true ;
300+ parent . AddChild ( allMethodsSection ) ;
301+ }
302+
303+ BuildMethod ( ) ;
314304 }
315305 }
316306 finally
@@ -1160,7 +1150,6 @@ private void BuildCallParameters(NonTerminalNode callNode)
11601150 {
11611151 NextLexem ( ) ; // съели открывающую скобку
11621152 WalkCallArguments ( node ) ;
1163-
11641153 NextLexem ( ) ; // съели закрывающую скобку
11651154 }
11661155 finally
@@ -1366,14 +1355,14 @@ private BslSyntaxNode SelectTerminalNode(in Lexem currentLexem, bool supportAwai
13661355 {
13671356 node = BuildNewObjectCreation ( ) ;
13681357 }
1369- else if ( currentLexem . Token == Token . Question )
1370- {
1371- node = BuildQuestionOperator ( ) ;
1372- }
13731358 else if ( LanguageDef . IsBuiltInFunction ( currentLexem . Token ) )
13741359 {
13751360 node = BuildGlobalCall ( currentLexem ) ;
13761361 }
1362+ else if ( currentLexem . Token == Token . Question )
1363+ {
1364+ node = BuildQuestionOperator ( ) ;
1365+ }
13771366 else if ( supportAwait && currentLexem . Token == Token . Await )
13781367 {
13791368 node = BuildExpressionAwaitOperator ( currentLexem ) ;
0 commit comments