MCPcopy Create free account
hub / github.com/anjo76/angelscript / ParseNamespace

Method ParseNamespace

sdk/angelscript/source/as_parser.cpp:2725–2800  ·  view source on GitHub ↗

BNF:1: NAMESPACE ::= 'namespace' IDENTIFIER ('::' IDENTIFIER)* '{' SCRIPT '}'

Source from the content-addressed store, hash-verified

2723
2724// BNF:1: NAMESPACE ::= 'namespace' IDENTIFIER ('::' IDENTIFIER)* '{' SCRIPT '}'
2725asCScriptNode *asCParser::ParseNamespace()
2726{
2727 asCScriptNode *node = CreateNode(snNamespace);
2728 if( node == 0 ) return 0;
2729
2730 sToken t1;
2731
2732 GetToken(&t1);
2733 if( t1.type == ttNamespace )
2734 node->UpdateSourcePos(t1.pos, t1.length);
2735 else
2736 {
2737 Error(ExpectedToken(asCTokenizer::GetDefinition(ttNamespace)), &t1);
2738 Error(InsteadFound(t1), &t1);
2739 }
2740
2741 node->AddChildLast(ParseIdentifier());
2742 if( isSyntaxError ) return node;
2743
2744 asCScriptNode *lowestNode = node;
2745 GetToken(&t1);
2746 while (t1.type == ttScope)
2747 {
2748 lowestNode->UpdateSourcePos(t1.pos, t1.length);
2749
2750 asCScriptNode *scopeNode = CreateNode(snScript);
2751 if (scopeNode == 0)
2752 return 0;
2753 lowestNode->AddChildLast(scopeNode);
2754
2755 lowestNode = CreateNode(snNamespace);
2756 if (lowestNode == 0)
2757 return 0;
2758
2759 scopeNode->AddChildLast(lowestNode);
2760 lowestNode->AddChildLast(ParseIdentifier());
2761 if (isSyntaxError)
2762 return node;
2763
2764 GetToken(&t1);
2765 }
2766
2767 if( t1.type == ttStartStatementBlock )
2768 node->UpdateSourcePos(t1.pos, t1.length);
2769 else
2770 {
2771 Error(ExpectedToken(asCTokenizer::GetDefinition(ttStartStatementBlock)), &t1);
2772 Error(InsteadFound(t1), &t1);
2773 return node;
2774 }
2775
2776 sToken start = t1;
2777
2778 lowestNode->AddChildLast(ParseScript(true));
2779
2780 if( !isSyntaxError )
2781 {
2782 GetToken(&t1);

Callers 1

SetDefaultNamespaceMethod · 0.45

Calls 2

UpdateSourcePosMethod · 0.80
AddChildLastMethod · 0.80

Tested by

no test coverage detected