/// <summary>
        /// Parses the given <paramref name="usingElement"/> and creates a <see cref="UsingBlockStatement"/> from it.
        /// </summary>
        /// <param name="usingElement">The SRC.Using element to parse.</param>
        /// <param name="context">The parser context to use.</param>
        /// <returns>A UsingBlockStatement created from the given usingElement.</returns>
        protected virtual UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context)
        {
            if (usingElement == null)
            {
                throw new ArgumentNullException("usingElement");
            }
            if (usingElement.Name != SRC.Using)
            {
                throw new ArgumentException("Must be a SRC.Using element", "usingElement");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var usingStmt = new UsingBlockStatement()
            {
                ProgrammingLanguage = ParserLanguage
            };

            usingStmt.AddLocation(context.CreateLocation(usingElement));

            foreach (var child in usingElement.Elements())
            {
                if (child.Name == SRC.Init)
                {
                    //TODO: waiting for update to srcml
                    usingStmt.Initializer = ParseExpression(GetChildExpressions(child), context);
                }
                else if (child.Name == SRC.Block)
                {
                    var blockStatements = child.Elements().Select(e => ParseStatement(e, context));
                    usingStmt.AddChildStatements(blockStatements);
                }
                else
                {
                    usingStmt.AddChildStatement(ParseStatement(child, context));
                }
            }

            return(usingStmt);
        }
예제 #2
0
        /// <summary>
        /// Parses the given <paramref name="usingElement"/> and creates a <see cref="UsingBlockStatement"/> from it.
        /// </summary>
        /// <param name="usingElement">The SRC.Using element to parse.</param>
        /// <param name="context">The parser context to use.</param>
        /// <returns>A UsingBlockStatement created from the given usingElement.</returns>
        protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) {
            if(usingElement == null)
                throw new ArgumentNullException("usingElement");
            if(usingElement.Name != SRC.Using_Stmt)
                throw new ArgumentException("Must be a SRC.Using element", "usingElement");
            if(context == null)
                throw new ArgumentNullException("context");

            var usingStmt = new UsingBlockStatement() {ProgrammingLanguage = ParserLanguage};
            usingStmt.AddLocation(context.CreateLocation(usingElement));

            foreach(var child in usingElement.Elements()) {
                if(child.Name == SRC.Init) {
                    //TODO: waiting for update to srcml
                    usingStmt.Initializer = ParseExpression(GetChildExpressions(child), context);
                }
                else if(child.Name == SRC.Block) {
                    var blockStatements = child.Elements().Select(e => ParseStatement(e, context));
                    usingStmt.AddChildStatements(blockStatements);
                } else {
                    usingStmt.AddChildStatement(ParseStatement(child, context));
                }
            }

            return usingStmt;
        }