Exemplo n.º 1
0
        public ASTNodeDeclStruct ParseDeclStruct()
        {
            var structNode = new ASTNodeDeclStruct();

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

            this.Match(TokenKind.KeywordStruct, "expected 'struct'");
            structNode.SetNameNode(this.ParseName(false, false));
            this.Match(TokenKind.BraceOpen, "expected '{'");

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

            // Parse fields.
            while (this.CurrentIsNot(TokenKind.BraceClose))
            {
                var fieldNode = new ASTNodeDeclStructField();
                fieldNode.SetSpan(this.Current().span);
                fieldNode.SetNameNode(this.ParseName(false, true));
                this.Match(TokenKind.Colon, "expected ':'");
                fieldNode.SetTypeNode(this.ParseType());
                structNode.AddFieldNode(fieldNode);

                this.MatchListSeparator(
                    TokenKind.Comma, TokenKind.BraceClose,
                    MessageCode.Expected, "expected ',' or '}'");
            }
            structNode.AddSpan(this.Current().span);
            this.Match(TokenKind.BraceClose, "expected '}'");

            return(structNode);
        }
Exemplo n.º 2
0
 public void AddFieldNode(ASTNodeDeclStructField field)
 {
     field.SetParent(this);
     this.AddSpan(field.GetSpan());
     this.fields.Add(field);
 }
Exemplo n.º 3
0
 public void AddFieldNode(ASTNodeDeclStructField field)
 {
     field.SetParent(this);
     this.AddSpan(field.GetSpan());
     this.fields.Add(field);
 }