Esempio n. 1
0
        IncludeDirective ParseIncludePath(ProjectItemCodeDocument codeDoc, CodeSegment segment)
        {
            string workingDir = Path.GetDirectoryName(_project.StartUpCodeDocument.FilePath);
            StringBuilder sb = new StringBuilder();

            CodeSegment next = segment;
            CodeSegment current = null;
            List<CodeSegment> _pathTokens = new List<CodeSegment>();
            while(next != null && next.Token != Token.NewLine) {
                current = next;
                next = next.Next;
                if(current.Token == Token.TraditionalString)
                    sb.Append(current.TokenString);
                else if(current.Token == Token.Deref) {
                    if(current.Next != null && current.Next.Token == Token.Identifier) {
                        if(current.Next.TokenString.Equals(WORKINGDIR_VAR, StringComparison.InvariantCultureIgnoreCase)) {
                            sb.Append(workingDir);
                        } else {
                            RegisterError(codeDoc, current.Next, "Unknown precompiler Variable!");
                        }
                        if(current.Next != null && current.Next.Next != null)
                            next = current.Next.Next.Next;
                    } else if(current.Next != null) {
                        RegisterError(codeDoc, current.Next, "Expected Identifier after Deref!");
                    }
                }
                if(current != null)
                    _pathTokens.Add(current);
            }
            var path = sb.ToString();

            try {
                if(!path.Contains(':')) {
                    path = Path.Combine(workingDir, path);
                }
            } catch {
                path = "";
            }

            var directive = new IncludeDirective() { ResolvedFilePath = path };
            CodeError fail = null;
            if(!File.Exists(path)){
                var err = string.Format("File not found!\n" + path);
                fail = new CodeError() { Description = err };
                if(_pathTokens.Any())
                    RegisterError(codeDoc, _pathTokens.First(), err);
            }
            foreach(var s in _pathTokens) {
                s.CodeDOMObject = directive;
                if(fail != null) {
                    s.ErrorContext = fail;
                }
            }
            return directive;
        }
Esempio n. 2
0
 protected void RegisterError(Projecting.ProjectItemCodeDocument codeitem, CodeSegment segment, string errorDescription) {
     var errorService = codeitem.Project.Solution.ErrorService;
     var err = new CodeError() { Description = errorDescription };
     if(segment != null) {
         segment.ErrorContext = err;
         errorService.Add(new Errors.ErrorItem(segment, codeitem, ErrorSource.DirectiveParser));
     } else {
         errorService.Add(new Errors.ErrorItem(err, codeitem, ErrorSource.DirectiveParser));
     }
 }