示例#1
0
        private static bool Include(CodeProcessorContext context, Stream data, List <FileDescriptor> referenceFiles, List <string> fileLookups, TokenStream nodes)
        {
            if (!Preprocessor.Whitespace(context, data, nodes))
            {
                return(Preprocessor.ThrowError(context, PreprocessorCodes.UnexpectedCharacter));
            }

            TokenStream target             = new TokenStream();
            Lazy <HashSet <UInt32> > stack = new Lazy <HashSet <UInt32> >();

            while (!Preprocessor.LineBreak(context, data, target))
            {
                Preprocessor.Process(context, data, target, stack, true);
            }

            if (Preprocessor.IncludeHeader(context, target, target))
            {
                fileLookups.Add(Encoding.UTF8.GetString(target.Buffer.ToArray()));
            }
            else if (Preprocessor.IncludeSource(context, target, target))
            {
                string         path = Encoding.UTF8.GetString(target.Buffer.ToArray());
                FileDescriptor file = FileDescriptor.Create(context.File.Location, path);
                if (file.Exists())
                {
                    referenceFiles.Add(file);
                }
                else
                {
                    fileLookups.Add(path);
                }
            }
            else
            {
                return(Preprocessor.ThrowError(context, PreprocessorCodes.ExpressionExpected));
            }
            return(true);
        }