Esempio n. 1
0
        public ASTNodeDeclGroup ParseDeclGroup()
        {
            var declGroupNode = new ASTNodeDeclGroup();

            declGroupNode.SetSpan(this.Current().span);

            // Parse use directives.
            while (!this.IsOver() && !this.CurrentIs(TokenKind.BraceClose) &&
                   this.CurrentIs(TokenKind.KeywordUse))
            {
                var useNode = this.ParseUseDirective();
                this.Match(TokenKind.Semicolon, "expected ';'");
                declGroupNode.AddUseNode(useNode);
            }

            // Parse namespaces, functs, and structs.
            while (!this.IsOver() && !this.CurrentIs(TokenKind.BraceClose))
            {
                /*var declName = this.ParseName(false, false);
                 * if (this.CurrentIs(TokenKind.DoubleColon) && this.NextIs(TokenKind.BraceOpen))
                 * {
                 *  this.Advance();
                 *  var namespaceNode = new ASTNodeDeclNamespace();
                 *  namespaceNode.SetPathNode(declName.path);
                 *
                 *  this.Match(TokenKind.BraceOpen, "expected '{'");
                 *  namespaceNode.SetInnerGroupNode(ParseDeclGroup());
                 *  this.Match(TokenKind.BraceClose, "expected '}'");
                 *
                 *  declGroupNode.AddNamespaceDeclNode(namespaceNode);
                 * }
                 * else
                 * {*/
                if (this.CurrentIs(TokenKind.KeywordFn))
                {
                    var fnNode = this.ParseDeclFunct(true);
                    declGroupNode.AddFunctDeclNode(fnNode);
                }

                else if (this.CurrentIs(TokenKind.KeywordStruct))
                {
                    var stNode = this.ParseDeclStruct();
                    declGroupNode.AddStructDeclNode(stNode);
                }

                else
                {
                    throw this.FatalBefore(MessageCode.Expected, "expected 'struct' or 'fn'");
                }
                //}
            }

            declGroupNode.AddSpan(this.Current().span);
            return(declGroupNode);
        }
Esempio n. 2
0
 public void SetInnerGroupNode(ASTNodeDeclGroup groupNode)
 {
     groupNode.SetParent(this);
     this.AddSpan(groupNode.GetSpan());
     this.innerGroup = groupNode;
 }
Esempio n. 3
0
 public void SetInnerGroupNode(ASTNodeDeclGroup groupNode)
 {
     groupNode.SetParent(this);
     this.AddSpan(groupNode.GetSpan());
     this.innerGroup = groupNode;
 }