@@ -551,7 +551,13 @@ void ParseStatements(List<SyntaxTree> list)
551551 case ( int ) TokenType . FUNCTION :
552552 statement = ParseFunctionStatement ( ) ; break ;
553553 case ( int ) TokenType . LOCAL :
554- statement = ParseLocalStatement ( ) ; break ;
554+ case ( int ) TokenType . GLOBAL :
555+ {
556+ var state = ParseScopeStatement ( ) ;
557+ state . is_global = token_ahead . EqualTo ( TokenType . GLOBAL ) ;
558+ statement = state ;
559+ break ;
560+ }
555561 case ( int ) TokenType . RETURN :
556562 statement = ParseReturnStatement ( ) ; break ;
557563 case ( int ) TokenType . BREAK :
@@ -781,21 +787,21 @@ ForInStatement ParseForInStatement()
781787 return statement ;
782788 }
783789
784- SyntaxTree ParseLocalStatement ( )
790+ ScopeStatement ParseScopeStatement ( )
785791 {
786792 NextToken ( ) ; // skip 'local'
787793
788794 if ( LookAhead ( ) . m_type == ( int ) TokenType . FUNCTION )
789- return ParseLocalFunction ( ) ;
795+ return ParseScopeFunction ( ) ;
790796 else if ( LookAhead ( ) . m_type == ( int ) TokenType . NAME )
791- return ParseLocalNameList ( ) ;
797+ return ParseScopeNameList ( ) ;
792798 else
793- throw NewParserException ( "unexpect token after 'local'" , _look_ahead ) ;
799+ throw NewParserException ( "unexpect token after 'local' or 'global' " , _look_ahead ) ;
794800 }
795- LocalFunctionStatement ParseLocalFunction ( )
801+ ScopeFunctionStatement ParseScopeFunction ( )
796802 {
797803 NextToken ( ) ; // skip 'function'
798- var statement = new LocalFunctionStatement ( _current . m_line ) ;
804+ var statement = new ScopeFunctionStatement ( _current . m_line ) ;
799805
800806 if ( NextToken ( ) . m_type != ( int ) TokenType . NAME )
801807 throw NewParserException ( "expect 'id' after 'local function'" , _current ) ;
@@ -804,9 +810,9 @@ LocalFunctionStatement ParseLocalFunction()
804810 statement . func_body = ParseFunctionBody ( ) ;
805811 return statement ;
806812 }
807- LocalNameListStatement ParseLocalNameList ( )
813+ ScopeNameListStatement ParseScopeNameList ( )
808814 {
809- var statement = new LocalNameListStatement ( _current . m_line ) ;
815+ var statement = new ScopeNameListStatement ( _current . m_line ) ;
810816 statement . name_list = ParseNameList ( ) ;
811817 if ( LookAhead ( ) . m_type == '=' )
812818 {
0 commit comments