Exemplo n.º 1
0
        public override IElement CreateCopy()
        {
            PreProcessorInclude e = new PreProcessorInclude();

            e.AddChildren(this.CopyChildren());

            e.Path = (Path)e.children[this.children.IndexOf(Path)];

            return(e);
        }
Exemplo n.º 2
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            PreProcessorInclude include = new PreProcessorInclude();
            int startIndex = parentInfo.CurrentIndex;

            MoveInfo moveInfo = new MoveInfo(parentInfo);

            moveInfo.Move(SearchDirection.LeftToRight); // "include"
            moveInfo.Move(SearchDirection.LeftToRight); // after "include"
            moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            Path path = Path.Parse(moveInfo, parsingInfo, scriptInfo);

            if (path == null)
            {
                throw new SyntaxException("Bad path", parentInfo.GetErrorInfo());
            }

            include.Path = path;

            moveInfo.Move(SearchDirection.LeftToRight);
            IElement terminal = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (terminal == null || !terminal.IsTT(TokenType.SemiColon))
            {
                throw new SyntaxException("Could not find ;", parentInfo.GetErrorInfo());
            }


            int             length   = (moveInfo.CurrentIndex + 1) - startIndex;
            List <IElement> children = parentInfo.CurrentElements.GetRange(startIndex, length);

            include.AddChildren(children);
            parentInfo.Replace(length, include);

            // include file
            string SFPath = path.ToString();

            if (scriptInfo.Includes.Find(a => a.SFPath.EqualCode(SFPath)) != null)
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("File '" + SFPath + "' already included",
                                      parentInfo.GetErrorInfo(include)));
            }

            ScriptFile includeFile = scriptInfo.SF.Manager.GetSF(SFPath);

            if (includeFile != null)
            {
                IncludeInfo includeInfo = new IncludeInfo(includeFile);
                scriptInfo.AddInclude(includeInfo);

                parsingInfo.IncludeDefList.Add(include);
            }
            else
            {
                scriptInfo.SF.Errors.Add(
                    new SemanticError("Could not include file '" + SFPath + "'",
                                      parentInfo.GetErrorInfo(include)));
            }
        }