Example #1
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)));
            }
        }