コード例 #1
0
        private ParsedDocument IdiotParse(string fileName, string content)
        {
            var    result    = new DefaultParsedDocument(fileName);
            int    beginLine = 0;
            string foldTitle = "";

            var lines = content.Split('\n');

            for (int linenum = 0; linenum < lines.Length; ++linenum)
            {
                var line   = lines[linenum];
                var t_line = line.Trim();

                int i;

                i = line.IndexOf("Процедура", StringComparison.InvariantCultureIgnoreCase);
                if (i != -1 && beginLine == 0)
                {
                    beginLine = linenum;
                    foldTitle = t_line;
                }

                i = line.IndexOf("КонецПроцедуры", StringComparison.InvariantCultureIgnoreCase);
                if (i != -1 && beginLine != 0)
                {
                    var begin = new DocumentLocation(beginLine + 1, 1);
                    var end   = new DocumentLocation(linenum + 1, line.Length);
                    result.Add(new FoldingRegion(foldTitle, new DocumentRegion(begin, end)));
                    beginLine = 0;
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: CDocumentParser.cs プロジェクト: Kalnor/monodevelop
		public override ParsedDocument Parse (bool storeAst, string fileName, TextReader reader, Project project = null)
		{
			var doc = new DefaultParsedDocument (fileName);
			doc.Flags |= ParsedDocumentFlags.NonSerializable;
			ProjectInformation pi = ProjectInformationManager.Instance.Get (project);
			
			string content = reader.ReadToEnd ();
			string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
			
			var globals = new DefaultUnresolvedTypeDefinition ("", GettextCatalog.GetString ("(Global Scope)"));
			lock (pi) {
				// Add containers to type list
				foreach (LanguageItem li in pi.Containers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						var tmp = AddLanguageItem (pi, globals, li, contentLines) as IUnresolvedTypeDefinition;
						if (null != tmp){ doc.TopLevelTypeDefinitions.Add (tmp); }
					}
				}
				
				// Add global category for unscoped symbols
				foreach (LanguageItem li in pi.InstanceMembers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						AddLanguageItem (pi, globals, li, contentLines);
					}
				}
			}
			
			doc.TopLevelTypeDefinitions.Add (globals);
			return doc;
		}
コード例 #3
0
		public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions options, System.Threading.CancellationToken cancellationToken)
		{
			var fileName = options.FileName;
			var project = options.Project;
			var doc = new DefaultParsedDocument (fileName);
			doc.Flags |= ParsedDocumentFlags.NonSerializable;
			ProjectInformation pi = ProjectInformationManager.Instance.Get (project);
			
			string content = options.Content.Text;
			string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None);
			
			var globals = new DefaultUnresolvedTypeDefinition ("", GettextCatalog.GetString ("(Global Scope)"));
			lock (pi) {
				// Add containers to type list
				foreach (LanguageItem li in pi.Containers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						var tmp = AddLanguageItem (pi, globals, li, contentLines) as IUnresolvedTypeDefinition;
						if (null != tmp){ /*doc.TopLevelTypeDefinitions.Add (tmp);*/ }
					}
				}
				
				// Add global category for unscoped symbols
				foreach (LanguageItem li in pi.InstanceMembers ()) {
					if (null == li.Parent && FilePath.Equals (li.File, fileName)) {
						AddLanguageItem (pi, globals, li, contentLines);
					}
				}
			}
			
			//doc.TopLevelTypeDefinitions.Add (globals);
			return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc);
		}
コード例 #4
0
        public override ParsedDocument Parse(bool storeAst, string fileName, TextReader reader, Project project = null)
        {
            var doc = new DefaultParsedDocument(fileName);

            doc.Flags |= ParsedDocumentFlags.NonSerializable;

            ProjectInformation pi = ProjectInformationManager.Instance.Get(project);

            var content = reader.ReadToEnd();

            var contentLines = content.Split(new [] { Environment.NewLine }, StringSplitOptions.None);

            lock (pi)
            {
                var file = pi.GetFile(fileName);

                var keys = new List <Tuple <Func <ParserContext, bool>, Func <ParserContext, bool>, HashSet <string> > > ();

                AddParser(keys, e => e.DocString == null, AddTag, "@");
                AddParser(keys, e => e.DocString == null, AddFeature, "Feature:");
                AddParser(keys, e => e.DocString == null && e.Feature != null, AddScenario, "Scenario:", "Scenario Outline:", "Background:");
                AddParser(keys, e => e.DocString == null && e.Scenario != null, AddExamples, "Examples:");
                AddParser(keys, e => e.DocString == null && e.Scenario != null && e.Examples == null, AddSteps, "Given", "When", "Then", "And", "But");
                AddParser(keys, e => e.DocString == null && e.Scenario != null && (e.Step != null || e.Examples != null) && e.Table == null, AddTable, "|");
                AddParser(keys, e => e.DocString == null && e.Scenario != null && (e.Step != null || e.Examples != null) && e.Table != null, AddTableRow, "|");
                AddParser(keys, e => e.Scenario != null && e.Step != null, AddDocString, "\"\"\"");

                var context = new ParserContext
                {
                    FileName = doc.FileName,
                    Errors   = doc.Errors,
                    Tags     = new List <string>(),
                    Features = new List <Feature>()
                };

                ExecuteParsers(context, keys, contentLines);

                file.Features = context.Features;
            }

            return(doc);
        }
コード例 #5
0
        public override ParsedDocument Parse(bool storeAst, string fileName, TextReader reader, Project project = null)
        {
            var doc = new DefaultParsedDocument (fileName);
            doc.Flags |= ParsedDocumentFlags.NonSerializable;

            ProjectInformation pi = ProjectInformationManager.Instance.Get (project);

            var content = reader.ReadToEnd ();

            var contentLines = content.Split (new []{Environment.NewLine}, StringSplitOptions.None);

            lock(pi)
            {
                var file = pi.GetFile(fileName);

                var keys = new List<Tuple<Func<ParserContext, bool>, Func<ParserContext, bool>, HashSet<string>>> ();

                AddParser (keys, e => e.DocString == null, AddTag, "@");
                AddParser (keys, e => e.DocString == null, AddFeature, "Feature:");
                AddParser (keys, e => e.DocString == null && e.Feature != null, AddScenario, "Scenario:", "Scenario Outline:", "Background:");
                AddParser (keys, e => e.DocString == null && e.Scenario != null, AddExamples, "Examples:");
                AddParser (keys, e => e.DocString == null && e.Scenario != null && e.Examples == null, AddSteps, "Given", "When", "Then", "And", "But");
                AddParser (keys, e => e.DocString == null && e.Scenario != null && (e.Step != null || e.Examples != null) && e.Table == null, AddTable, "|");
                AddParser (keys, e => e.DocString == null && e.Scenario != null && (e.Step != null || e.Examples != null) && e.Table != null, AddTableRow, "|");
                AddParser (keys, e => e.Scenario != null && e.Step != null, AddDocString, "\"\"\"");

                var context = new ParserContext
                {
                    FileName = doc.FileName,
                    Errors = doc.Errors,
                    Tags = new List<string>(),
                    Features = new List<Feature>()
                };

                ExecuteParsers (context, keys, contentLines);

                file.Features = context.Features;
            }

            return doc;
        }
コード例 #6
0
        public override ParsedDocument Parse(bool storeAst, string fileName, TextReader reader, Project project = null)
        {
            var doc = new DefaultParsedDocument(fileName);

            doc.Flags |= ParsedDocumentFlags.NonSerializable;
            ProjectInformation pi = ProjectInformationManager.Instance.Get(project);

            string content = reader.ReadToEnd();

            string[] contentLines = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            var globals = new DefaultUnresolvedTypeDefinition("", GettextCatalog.GetString("(Global Scope)"));

            lock (pi) {
                // Add containers to type list
                foreach (LanguageItem li in pi.Containers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        var tmp = AddLanguageItem(pi, globals, li, contentLines) as IUnresolvedTypeDefinition;
                        if (null != tmp)
                        {
                            doc.TopLevelTypeDefinitions.Add(tmp);
                        }
                    }
                }

                // Add global category for unscoped symbols
                foreach (LanguageItem li in pi.InstanceMembers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        AddLanguageItem(pi, globals, li, contentLines);
                    }
                }
            }

            doc.TopLevelTypeDefinitions.Add(globals);
            return(doc);
        }
コード例 #7
0
        public override System.Threading.Tasks.Task <ParsedDocument> Parse(ParseOptions options, System.Threading.CancellationToken cancellationToken)
        {
            var fileName = options.FileName;
            var project  = options.Project;
            var doc      = new DefaultParsedDocument(fileName);

            doc.Flags |= ParsedDocumentFlags.NonSerializable;
            ProjectInformation pi = ProjectInformationManager.Instance.Get(project);

            string content = options.Content.Text;

            string[] contentLines = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            var globals = new DefaultUnresolvedTypeDefinition("", GettextCatalog.GetString("(Global Scope)"));

            lock (pi) {
                // Add containers to type list
                foreach (LanguageItem li in pi.Containers())
                {
                    if (null == li.Parent && FilePath.Equals(li.File, fileName))
                    {
                        var tmp = AddLanguageItem(pi, globals, li, contentLines) as IUnresolvedTypeDefinition;
                        if (null != tmp) /*doc.TopLevelTypeDefinitions.Add (tmp);*/ } {
                }
            }

            // Add global category for unscoped symbols
            foreach (LanguageItem li in pi.InstanceMembers())
            {
                if (null == li.Parent && FilePath.Equals(li.File, fileName))
                {
                    AddLanguageItem(pi, globals, li, contentLines);
                }
            }
        }

        //doc.TopLevelTypeDefinitions.Add (globals);
        return(System.Threading.Tasks.Task.FromResult((ParsedDocument)doc));
    }
コード例 #8
0
        ParsedDocument ITypeSystemParser.Parse(bool storeAst, string fileName, TextReader textReader, Project project = null)
        {
            var doc = new DefaultParsedDocument(fileName);

            DefaultUnresolvedTypeDefinition currentFile   = null;
            DefaultUnresolvedProperty       currentRegion = null;

            string eol      = Environment.NewLine;
            string content  = textReader.ReadToEnd();
            Match  eolMatch = eolExpression.Match(content);

            if (eolMatch != null && eolMatch.Success)
            {
                eol = eolMatch.Groups ["eol"].Value;
            }

            string[] lines   = content.Split(new string[] { eol }, StringSplitOptions.None);
            int      linenum = 1;
            Match    lineMatch;

            foreach (string line in lines)
            {
                lineMatch = fileHeaderExpression.Match(line.Trim());
                if (lineMatch != null && lineMatch.Success)
                {
                    if (currentFile != null)                     // Close out previous file region
                    {
                        currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.BeginLine,
                                                               currentFile.BodyRegion.BeginColumn,
                                                               linenum - 1, int.MaxValue);
                    }
                    if (currentRegion != null)                     // Close out previous chunk region
                    {
                        currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                                 currentRegion.BodyRegion.BeginColumn,
                                                                 linenum - 1, int.MaxValue);
                    }

                    // Create new file region
                    currentFile        = new DefaultUnresolvedTypeDefinition(string.Empty, string.Empty);
                    currentFile.Region = currentFile.BodyRegion = new DomRegion(lastToken(lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
                    doc.TopLevelTypeDefinitions.Add(currentFile);
                }
                else
                {
                    lineMatch = chunkExpression.Match(line);
                    if (lineMatch != null && lineMatch.Success && currentFile != null)
                    {
                        if (currentRegion != null)                         // Close out previous chunk region
                        {
                            currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                                     currentRegion.BodyRegion.BeginColumn,
                                                                     linenum - 1, int.MaxValue);
                        }

                        // Create new chunk region
                        currentRegion        = new DefaultUnresolvedProperty(currentFile, lineMatch.Groups ["chunk"].Value);
                        currentRegion.Region = currentRegion.BodyRegion = new DomRegion(currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
                        currentFile.Members.Add(currentRegion);
                    }
                }
                ++linenum;
            }

            // Close out trailing regions
            if (currentFile != null)
            {
                currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.BeginLine,
                                                       currentFile.BodyRegion.BeginColumn,
                                                       Math.Max(1, linenum - 2), int.MaxValue);
            }
            if (currentRegion != null)
            {
                currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                         currentRegion.BodyRegion.BeginColumn,
                                                         Math.Max(1, linenum - 2), int.MaxValue);
            }

            return(doc);
        }
コード例 #9
0
ファイル: MoonlightParser.cs プロジェクト: Kalnor/monodevelop
		static void GenerateCU (XmlParsedDocument doc)
		{
			if (doc.XDocument == null || doc.XDocument.RootElement == null) {
				doc.Add (new Error (ErrorType.Error, "No root node found.", 1, 1));
				return;
			}

			XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
			if (rootClass == null) {
				doc.Add (new Error (ErrorType.Error, "Root node does not contain an x:Class attribute.", 1, 1));
				return;
			}

			bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
			
			string rootNamespace, rootType, rootAssembly;
			XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);

			var cu = new DefaultParsedDocument (doc.FileName);

			DomRegion rootRegion = doc.XDocument.RootElement.Region;
			if (doc.XDocument.RootElement.IsClosed)
				rootRegion = new DomRegion (doc.XDocument.RootElement.Region.FileName, doc.XDocument.RootElement.Region.Begin, doc.XDocument.RootElement.ClosingTag.Region.End); 
			
			var declType = new DefaultUnresolvedTypeDefinition (rootNamespace, rootType) {
				Kind = TypeKind.Class,
				Accessibility = Accessibility.Public,
				Region = rootRegion
			};
			cu.TopLevelTypeDefinitions.Add (declType);
			
			var initcomp = new DefaultUnresolvedMethod (declType, "InitializeComponent") {
				ReturnType = KnownTypeReference.Void,
				Accessibility = Accessibility.Public
			};
			declType.Members.Add (initcomp);
			
			var _contentLoaded = new DefaultUnresolvedField (declType, "_contentLoaded") {
				ReturnType = KnownTypeReference.Boolean
			};
// was missing in the original code: correct ? 
//			declType.Fields.Add (_contentLoaded);

			if (isApplication)
				return;
			
//			cu.Add (new DomUsing (DomRegion.Empty, "System"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
			
	//		Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
	//		namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
			
			XName nameAtt = new XName ("x", "Name");
			
			foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
				XAttribute name = el.Attributes [nameAtt];
				if (name != null && name.IsComplete) {
					string type = ResolveType (el);
					if (type == null || type.Length == 0)
						cu.Add (new Error (ErrorType.Error, "Could not find namespace for '" + el.Name.FullName + "'.", el.Region.Begin));
					else
						declType.Members.Add (new DefaultUnresolvedField (declType, name.Value) {
							Accessibility = Accessibility.Internal,
							Region = el.Region,
							ReturnType = new DefaultUnresolvedTypeDefinition (type)
						});
				}
			}
		}
コード例 #10
0
        public unsafe ParsedDocument Parse(string fileName, string content)
        {
            var  regionStack = new Stack <Tuple <string, DocumentLocation> > ();
            var  result = new DefaultParsedDocument(fileName);
            bool inSingleComment = false, inMultiLineComment = false;
            bool inString = false, inVerbatimString = false;
            bool inChar = false;
            bool inLineStart = true, hasStartedAtLine = false;
            int  line = 1, column = 1;
            var  startLoc = DocumentLocation.Empty;

            content.UnsafeApply(
                (bytePtr) => {
                byte *startPtr = bytePtr.Value;
                byte *endPtr   = startPtr + content.Length;
                byte *ptr      = startPtr;
                byte *beginPtr = ptr;
                while (ptr < endPtr)
                {
                    switch ((char)*ptr)
                    {
                    case '#':
                        if (!inLineStart)
                        {
                            break;
                        }
                        inLineStart = false;
                        ptr++;

                        if (StartsIdentifier(ptr, endPtr, "region"))
                        {
                            var regionLocation = new DocumentLocation(line, column);
                            column++;
                            ptr    += "region".Length;
                            column += "region".Length;
                            SkipWhitespaces(ref ptr, endPtr, ref column);
                            regionStack.Push(Tuple.Create(ReadToEol(content, startPtr, ref ptr, endPtr, ref line, ref column), regionLocation));
                            continue;
                        }
                        else if (StartsIdentifier(ptr, endPtr, "endregion"))
                        {
                            column++;
                            ptr    += "endregion".Length;
                            column += "endregion".Length;
                            if (regionStack.Count > 0)
                            {
                                var beginRegion = regionStack.Pop();
                                result.Add(new FoldingRegion(
                                               beginRegion.Item1,
                                               new DocumentRegion(beginRegion.Item2.Line, beginRegion.Item2.Column, line, column),
                                               FoldType.UserRegion,
                                               true));
                            }
                            continue;
                        }
                        else
                        {
                            column++;
                        }
                        break;

                    case '/':
                        if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment)
                        {
                            inLineStart = false;
                            break;
                        }
                        if (ptr + 1 < endPtr)
                        {
                            char nextCh = (char)*(ptr + 1);
                            if (nextCh == '/')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inSingleComment = true;
                            }
                            else if (nextCh == '*')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inMultiLineComment = true;
                            }
                        }
                        inLineStart = false;
                        break;

                    case '*':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment)
                        {
                            break;
                        }
                        if (inMultiLineComment && ptr + 1 < endPtr)
                        {
                            if (ptr + 1 < endPtr && (char)*(ptr + 1) == '/')
                            {
                                ptr               += 2;
                                column            += 2;
                                inMultiLineComment = false;
                                result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                                {
                                    Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                    OpenTag           = "/*",
                                    CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.Block,
                                    Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                    CommentStartsLine = hasStartedAtLine
                                });
                                continue;
                            }
                        }
                        break;

                    case '@':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
                        {
                            break;
                        }
                        if (ptr + 1 < endPtr && (char)*(ptr + 1) == '"')
                        {
                            ptr++;
                            column++;
                            inVerbatimString = true;
                        }
                        break;

                    case '\n':
                        if (inSingleComment && hasStartedAtLine)
                        {
                            bool isDocumentation = (char)*beginPtr == '/';
                            if (isDocumentation)
                            {
                                beginPtr++;
                            }

                            result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                            {
                                Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.SingleLine,
                                OpenTag           = "//",
                                Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                CommentStartsLine = hasStartedAtLine,
                                IsDocumentation   = isDocumentation
                            });
                            inSingleComment = false;
                        }
                        inString    = false;
                        inChar      = false;
                        inLineStart = true;
                        line++;
                        column = 1;
                        ptr++;
                        continue;

                    case '\r':
                        if (ptr + 1 < endPtr && (char)*(ptr + 1) == '\n')
                        {
                            ptr++;
                        }
                        goto case '\n';

                    case '\\':
                        if (inString || inChar)
                        {
                            ptr++;
                        }
                        break;

                    case '"':
                        if (inSingleComment || inMultiLineComment || inChar)
                        {
                            break;
                        }
                        if (inVerbatimString)
                        {
                            if (ptr + 1 < endPtr && (char)*(ptr + 1) == '"')
                            {
                                ptr++;
                                column++;
                                break;
                            }
                            inVerbatimString = false;
                            break;
                        }
                        inString = !inString;
                        break;

                    case '\'':
                        if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
                        {
                            break;
                        }
                        inChar = !inChar;
                        break;

                    default:
                        inLineStart &= (char)*ptr == ' ' || (char)*ptr == '\t';
                        break;
                    }

                    column++;
                    ptr++;
                }
            },
                (charPtr) => {
                char *startPtr = charPtr.Value;
                char *endPtr   = startPtr + content.Length;
                char *ptr      = startPtr;
                char *beginPtr = ptr;
                while (ptr < endPtr)
                {
                    switch (*ptr)
                    {
                    case '#':
                        if (!inLineStart)
                        {
                            break;
                        }
                        inLineStart = false;
                        ptr++;

                        if (StartsIdentifier(ptr, endPtr, "region"))
                        {
                            var regionLocation = new DocumentLocation(line, column);
                            column++;
                            ptr    += "region".Length;
                            column += "region".Length;
                            SkipWhitespaces(ref ptr, endPtr, ref column);
                            regionStack.Push(Tuple.Create(ReadToEol(content, startPtr, ref ptr, endPtr, ref line, ref column), regionLocation));
                            continue;
                        }
                        else if (StartsIdentifier(ptr, endPtr, "endregion"))
                        {
                            column++;
                            ptr    += "endregion".Length;
                            column += "endregion".Length;
                            if (regionStack.Count > 0)
                            {
                                var beginRegion = regionStack.Pop();
                                result.Add(new FoldingRegion(
                                               beginRegion.Item1,
                                               new DocumentRegion(beginRegion.Item2.Line, beginRegion.Item2.Column, line, column),
                                               FoldType.UserRegion,
                                               true));
                            }
                            continue;
                        }
                        else
                        {
                            column++;
                        }
                        break;

                    case '/':
                        if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment)
                        {
                            inLineStart = false;
                            break;
                        }
                        if (ptr + 1 < endPtr)
                        {
                            char nextCh = *(ptr + 1);
                            if (nextCh == '/')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inSingleComment = true;
                            }
                            else if (nextCh == '*')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inMultiLineComment = true;
                            }
                        }
                        inLineStart = false;
                        break;

                    case '*':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment)
                        {
                            break;
                        }
                        if (inMultiLineComment && ptr + 1 < endPtr)
                        {
                            if (ptr + 1 < endPtr && *(ptr + 1) == '/')
                            {
                                ptr               += 2;
                                column            += 2;
                                inMultiLineComment = false;
                                result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                                {
                                    Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                    OpenTag           = "/*",
                                    CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.Block,
                                    Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                    CommentStartsLine = hasStartedAtLine
                                });
                                continue;
                            }
                        }
                        break;

                    case '@':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
                        {
                            break;
                        }
                        if (ptr + 1 < endPtr && *(ptr + 1) == '"')
                        {
                            ptr++;
                            column++;
                            inVerbatimString = true;
                        }
                        break;

                    case '\n':
                        if (inSingleComment && hasStartedAtLine)
                        {
                            bool isDocumentation = *beginPtr == '/';
                            if (isDocumentation)
                            {
                                beginPtr++;
                            }

                            result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                            {
                                Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.SingleLine,
                                OpenTag           = "//",
                                Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                CommentStartsLine = hasStartedAtLine,
                                IsDocumentation   = isDocumentation
                            });
                            inSingleComment = false;
                        }
                        inString    = false;
                        inChar      = false;
                        inLineStart = true;
                        line++;
                        column = 1;
                        ptr++;
                        continue;

                    case '\r':
                        if (ptr + 1 < endPtr && *(ptr + 1) == '\n')
                        {
                            ptr++;
                        }
                        goto case '\n';

                    case '\\':
                        if (inString || inChar)
                        {
                            ptr++;
                        }
                        break;

                    case '"':
                        if (inSingleComment || inMultiLineComment || inChar)
                        {
                            break;
                        }
                        if (inVerbatimString)
                        {
                            if (ptr + 1 < endPtr && *(ptr + 1) == '"')
                            {
                                ptr++;
                                column++;
                                break;
                            }
                            inVerbatimString = false;
                            break;
                        }
                        inString = !inString;
                        break;

                    case '\'':
                        if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
                        {
                            break;
                        }
                        inChar = !inChar;
                        break;

                    default:
                        inLineStart &= *ptr == ' ' || *ptr == '\t';
                        break;
                    }

                    column++;
                    ptr++;
                }
            });
            foreach (var fold in result.GetCommentsAsync().Result.ToFolds())
            {
                result.Add(fold);
            }
            return(result);
        }
コード例 #11
0
ファイル: DiffParser.cs プロジェクト: Kalnor/monodevelop
		public override ParsedDocument Parse (bool storeAst, string fileName, TextReader textReader, Project project = null)
		{
			var doc = new DefaultParsedDocument (fileName);
			
			DefaultUnresolvedTypeDefinition currentFile = null;
			DefaultUnresolvedProperty currentRegion = null;
			
			string eol = Environment.NewLine;
			string content = textReader.ReadToEnd ();
			Match eolMatch = eolExpression.Match (content);
			if (eolMatch != null && eolMatch.Success)
				eol = eolMatch.Groups ["eol"].Value;
			
			string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None);
			int linenum = 1;
			Match lineMatch;
			foreach (string line in lines) {
				lineMatch = fileHeaderExpression.Match (line.Trim ());
				if (lineMatch != null && lineMatch.Success) {
					if (currentFile != null) // Close out previous file region
						currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
						                                        currentFile.BodyRegion.BeginColumn,
						                                        linenum - 1, int.MaxValue);
					if (currentRegion != null) // Close out previous chunk region
						currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
						                                          currentRegion.BodyRegion.BeginColumn,
						                                          linenum - 1, int.MaxValue);
					
					// Create new file region
					currentFile = new DefaultUnresolvedTypeDefinition (string.Empty, string.Empty);
					currentFile.Region = currentFile.BodyRegion = new DomRegion (lastToken (lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
					doc.TopLevelTypeDefinitions.Add (currentFile);
				} else {
					lineMatch = chunkExpression.Match (line);
					if (lineMatch != null && lineMatch.Success && currentFile != null) {
						if (currentRegion != null) // Close out previous chunk region
							currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
							                                          currentRegion.BodyRegion.BeginColumn,
							                                          linenum - 1, int.MaxValue);
						
						// Create new chunk region
						currentRegion = new DefaultUnresolvedProperty (currentFile, lineMatch.Groups ["chunk"].Value);
						currentRegion.Region = currentRegion.BodyRegion = new DomRegion (currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
						currentFile.Members.Add (currentRegion);
					}
				}
				++linenum;
			}
			
			// Close out trailing regions
			if (currentFile != null)
				currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
				                                        currentFile.BodyRegion.BeginColumn, 
				                                        Math.Max (1, linenum - 2), int.MaxValue);
			if (currentRegion != null)
				currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
				                                          currentRegion.BodyRegion.BeginColumn, 
				                                          Math.Max (1, linenum - 2), int.MaxValue);
			
			return doc;
		}
コード例 #12
0
		public unsafe ParsedDocument Parse (string fileName, string content)
		{
			var regionStack = new Stack<Tuple<string, DocumentLocation>> ();
			var result = new DefaultParsedDocument (fileName);
			bool inSingleComment = false, inMultiLineComment = false;
			bool inString = false, inVerbatimString = false;
			bool inChar = false;
			bool inLineStart = true, hasStartedAtLine = false;
			int line = 1, column = 1;
			var startLoc = DocumentLocation.Empty;
			
			fixed (char* startPtr = content) {
				char* endPtr = startPtr + content.Length;
				char* ptr = startPtr;
				char* beginPtr = ptr;
				while (ptr < endPtr) {
					switch (*ptr) {
					case '#':
						if (!inLineStart)
							break;
						inLineStart = false;
						ptr++;

						if (StartsIdentifier (ptr, endPtr, "region")) {
							var regionLocation = new DocumentLocation (line, column);
							column++;
							ptr += "region".Length;
							column += "region".Length;
							SkipWhitespaces (ref ptr, endPtr, ref column);
							regionStack.Push (Tuple.Create (ReadToEol (content, ref ptr, endPtr, ref line, ref column), regionLocation));
							continue;
						} else if (StartsIdentifier (ptr, endPtr, "endregion")) {
							column++;
							ptr += "endregion".Length;
							column += "endregion".Length;
							if (regionStack.Count > 0) {
								var beginRegion = regionStack.Pop ();
								result.Add (new FoldingRegion (
									beginRegion.Item1, 
									new DocumentRegion (beginRegion.Item2.Line, beginRegion.Item2.Column, line, column),
									FoldType.UserRegion,
									true));
							}
							continue;
						} else {
							column++;
						}
						break;
					case '/':
						if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment) {
							inLineStart = false;
							break;
						}
						if (ptr + 1 < endPtr) {
							char nextCh = *(ptr + 1);
							if (nextCh == '/') {
								hasStartedAtLine = inLineStart;
								beginPtr = ptr + 2;
								startLoc = new DocumentLocation (line, column);
								ptr++;
								column++;
								inSingleComment = true;
							} else if (nextCh == '*') {
								hasStartedAtLine = inLineStart;
								beginPtr = ptr + 2;
								startLoc = new DocumentLocation (line, column);
								ptr++;
								column++;
								inMultiLineComment = true;
							}
						}
						inLineStart = false;
						break;
					case '*':
						inLineStart = false;
						if (inString || inChar || inVerbatimString || inSingleComment)
							break;
						if (inMultiLineComment && ptr + 1 < endPtr) {
							if (ptr + 1 < endPtr && *(ptr + 1) == '/') {
								ptr += 2;
								column += 2;
								inMultiLineComment = false;
								result.Add (new MonoDevelop.Ide.TypeSystem.Comment () {
									Region = new DocumentRegion (startLoc, new DocumentLocation (line, column)),
									OpenTag = "/*",
									CommentType = MonoDevelop.Ide.TypeSystem.CommentType.Block,
									Text = content.Substring ((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
									CommentStartsLine = hasStartedAtLine
								});
								continue;
							}
						}
						break;
					case '@':
						inLineStart = false;
						if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
							break;
						if (ptr + 1 < endPtr && *(ptr + 1) == '"') {
							ptr++;
							column++;
							inVerbatimString = true;
						}
						break;
					case '\n':
						if (inSingleComment && hasStartedAtLine) {
							bool isDocumentation = *beginPtr == '/';
							if (isDocumentation)
								beginPtr++;
							
							result.Add (new MonoDevelop.Ide.TypeSystem.Comment () { 
								Region = new DocumentRegion (startLoc, new DocumentLocation (line, column)),
								CommentType = MonoDevelop.Ide.TypeSystem.CommentType.SingleLine, 
								OpenTag = "//",
								Text = content.Substring ((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
								CommentStartsLine = hasStartedAtLine,
								IsDocumentation = isDocumentation
							});
							inSingleComment = false;
						}
						inString = false;
						inChar = false;
						inLineStart = true;
						line++;
						column = 1;
						ptr++;
						continue;
					case '\r':
						if (ptr + 1 < endPtr && *(ptr + 1) == '\n')
							ptr++;
						goto case '\n';
					case '\\':
						if (inString || inChar)
							ptr++;
						break;
					case '"':
						if (inSingleComment || inMultiLineComment || inChar)
							break;
						if (inVerbatimString) {
							if (ptr + 1 < endPtr && *(ptr + 1) == '"') {
								ptr++;
								column++;
								break;
							}
							inVerbatimString = false;
							break;
						}
						inString = !inString;
						break;
					case '\'':
						if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
							break;
						inChar = !inChar;
						break;
					default:
						inLineStart &= *ptr == ' ' || *ptr == '\t';
						break;
					}

					column++;
					ptr++;
				}
			}
			foreach (var fold in result.GetCommentsAsync().Result.ToFolds ()) {
				result.Add (fold);
			}
			return result;
		}
コード例 #13
0
        static void GenerateCU(XmlParsedDocument doc)
        {
            if (doc.XDocument == null || doc.XDocument.RootElement == null)
            {
                doc.Add(new Error(ErrorType.Error, "No root node found.", 1, 1));
                return;
            }

            XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName("x", "Class")];

            if (rootClass == null)
            {
                doc.Add(new Error(ErrorType.Error, "Root node does not contain an x:Class attribute.", 1, 1));
                return;
            }

            bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";

            string rootNamespace, rootType, rootAssembly;

            XamlG.ParseXmlns(rootClass.Value, out rootType, out rootNamespace, out rootAssembly);

            var cu = new DefaultParsedDocument(doc.FileName);

            DomRegion rootRegion = doc.XDocument.RootElement.Region;

            if (doc.XDocument.RootElement.IsClosed)
            {
                rootRegion = new DomRegion(doc.XDocument.RootElement.Region.FileName, doc.XDocument.RootElement.Region.Begin, doc.XDocument.RootElement.ClosingTag.Region.End);
            }

            var declType = new DefaultUnresolvedTypeDefinition(rootNamespace, rootType)
            {
                Kind          = TypeKind.Class,
                Accessibility = Accessibility.Public,
                Region        = rootRegion
            };

            cu.TopLevelTypeDefinitions.Add(declType);

            var initcomp = new DefaultUnresolvedMethod(declType, "InitializeComponent")
            {
                ReturnType    = KnownTypeReference.Void,
                Accessibility = Accessibility.Public
            };

            declType.Members.Add(initcomp);

            var _contentLoaded = new DefaultUnresolvedField(declType, "_contentLoaded")
            {
                ReturnType = KnownTypeReference.Boolean
            };

// was missing in the original code: correct ?
//			declType.Fields.Add (_contentLoaded);

            if (isApplication)
            {
                return;
            }

//			cu.Add (new DomUsing (DomRegion.Empty, "System"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));

            //		Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
            //		namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";

            XName nameAtt = new XName("x", "Name");

            foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements)
            {
                XAttribute name = el.Attributes [nameAtt];
                if (name != null && name.IsComplete)
                {
                    string type = ResolveType(el);
                    if (type == null || type.Length == 0)
                    {
                        cu.Add(new Error(ErrorType.Error, "Could not find namespace for '" + el.Name.FullName + "'.", el.Region.Begin));
                    }
                    else
                    {
                        declType.Members.Add(new DefaultUnresolvedField(declType, name.Value)
                        {
                            Accessibility = Accessibility.Internal,
                            Region        = el.Region,
                            ReturnType    = new DefaultUnresolvedTypeDefinition(type)
                        });
                    }
                }
            }
        }
コード例 #14
0
        public unsafe ParsedDocument Parse(string fileName, string content)
        {
            var  regionStack = new Stack <Tuple <string, DocumentLocation> > ();
            var  result = new DefaultParsedDocument(fileName);
            bool inSingleComment = false, inMultiLineComment = false;
            bool inString = false, inVerbatimString = false;
            bool inChar = false;
            bool inLineStart = true, hasStartedAtLine = false;
            int  line = 1, column = 1;
            int  bracketDepth = 0;
            var  startLoc     = DocumentLocation.Empty;

            fixed(char *startPtr = content)
            {
                char *endPtr   = startPtr + content.Length;
                char *ptr      = startPtr;
                char *beginPtr = ptr;

                while (ptr < endPtr)
                {
                    switch (*ptr)
                    {
                    case '{':
                        if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment)
                        {
                            break;
                        }
                        bracketDepth++;
                        break;

                    case '}':
                        if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment)
                        {
                            break;
                        }
                        bracketDepth--;
                        break;

                    case '#':
                        if (!inLineStart)
                        {
                            break;
                        }
                        inLineStart = false;
                        ptr++;

                        if (StartsIdentifier(ptr, endPtr, "region"))
                        {
                            var regionLocation = new DocumentLocation(line, column);
                            column++;
                            ptr    += "region".Length;
                            column += "region".Length;
                            SkipWhitespaces(ref ptr, endPtr, ref column);
                            regionStack.Push(Tuple.Create(ReadToEol(content, ref ptr, endPtr, ref line, ref column), regionLocation));
                            continue;
                        }
                        else if (StartsIdentifier(ptr, endPtr, "endregion"))
                        {
                            column++;
                            ptr    += "endregion".Length;
                            column += "endregion".Length;
                            if (regionStack.Count > 0)
                            {
                                var beginRegion = regionStack.Pop();
                                result.Add(new FoldingRegion(
                                               beginRegion.Item1,
                                               new DocumentRegion(beginRegion.Item2.Line, beginRegion.Item2.Column, line, column),
                                               FoldType.UserRegion,
                                               true));
                            }
                            continue;
                        }
                        else
                        {
                            column++;
                        }
                        break;

                    case '/':
                        if (inString || inChar || inVerbatimString || inMultiLineComment || inSingleComment)
                        {
                            inLineStart = false;
                            break;
                        }
                        if (ptr + 1 < endPtr)
                        {
                            char nextCh = *(ptr + 1);
                            if (nextCh == '/')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inSingleComment = true;
                            }
                            else if (nextCh == '*')
                            {
                                hasStartedAtLine = inLineStart;
                                beginPtr         = ptr + 2;
                                startLoc         = new DocumentLocation(line, column);
                                ptr++;
                                column++;
                                inMultiLineComment = true;
                            }
                        }
                        inLineStart = false;
                        break;

                    case '*':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment)
                        {
                            break;
                        }
                        if (inMultiLineComment && ptr + 1 < endPtr)
                        {
                            if (ptr + 1 < endPtr && *(ptr + 1) == '/')
                            {
                                ptr               += 2;
                                column            += 2;
                                inMultiLineComment = false;
                                result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                                {
                                    Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                    OpenTag           = "/*",
                                    CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.Block,
                                    Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                    CommentStartsLine = hasStartedAtLine
                                });
                                continue;
                            }
                        }
                        break;

                    case '@':
                        inLineStart = false;
                        if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
                        {
                            break;
                        }
                        if (ptr + 1 < endPtr && *(ptr + 1) == '"')
                        {
                            ptr++;
                            column++;
                            inVerbatimString = true;
                        }
                        break;

                    case '\n':
                        if (inSingleComment && hasStartedAtLine)
                        {
                            bool isDocumentation = *beginPtr == '/';
                            if (isDocumentation)
                            {
                                beginPtr++;
                            }
                            if (isDocumentation || bracketDepth <= 1)
                            {
                                // Doesn't matter much that some comments are not correctly recognized - they'll get added later
                                // It's important that header comments are in.
                                result.Add(new MonoDevelop.Ide.TypeSystem.Comment()
                                {
                                    Region            = new DocumentRegion(startLoc, new DocumentLocation(line, column)),
                                    CommentType       = MonoDevelop.Ide.TypeSystem.CommentType.SingleLine,
                                    OpenTag           = "//",
                                    Text              = content.Substring((int)(beginPtr - startPtr), (int)(ptr - beginPtr)),
                                    CommentStartsLine = hasStartedAtLine,
                                    IsDocumentation   = isDocumentation
                                });
                            }
                            inSingleComment = false;
                        }
                        inString    = false;
                        inChar      = false;
                        inLineStart = true;
                        line++;
                        column = 1;
                        ptr++;
                        continue;

                    case '\r':
                        if (ptr + 1 < endPtr && *(ptr + 1) == '\n')
                        {
                            ptr++;
                        }
                        goto case '\n';

                    case '\\':
                        if (inString || inChar)
                        {
                            ptr++;
                        }
                        break;

                    case '"':
                        if (inSingleComment || inMultiLineComment || inChar)
                        {
                            break;
                        }
                        if (inVerbatimString)
                        {
                            if (ptr + 1 < endPtr && *(ptr + 1) == '"')
                            {
                                ptr++;
                                column++;
                                break;
                            }
                            inVerbatimString = false;
                            break;
                        }
                        inString = !inString;
                        break;

                    case '\'':
                        if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
                        {
                            break;
                        }
                        inChar = !inChar;
                        break;

                    default:
                        inLineStart &= *ptr == ' ' || *ptr == '\t';
                        break;
                    }

                    column++;
                    ptr++;
                }
            }

            foreach (var fold in ToFolds(result.GetCommentsAsync().Result))
            {
                result.Add(fold);
            }
            return(result);
        }
コード例 #15
0
ファイル: DiffParser.cs プロジェクト: noah1510/dotdevelop
        public override System.Threading.Tasks.Task <ParsedDocument> Parse(ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken)
        {
            ParsedDocument doc = new DefaultParsedDocument(parseOptions.FileName);

            return(System.Threading.Tasks.Task.FromResult(doc));
        }
コード例 #16
0
		public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken)
		{
			ParsedDocument doc = new DefaultParsedDocument (parseOptions.FileName);
			
			DefaultUnresolvedTypeDefinition currentFile = null;
			DefaultUnresolvedProperty currentRegion = null;
			
			string eol = Environment.NewLine;
			string content = parseOptions.Content.Text;
			Match eolMatch = eolExpression.Match (content);
			if (eolMatch != null && eolMatch.Success)
				eol = eolMatch.Groups ["eol"].Value;
			
			string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None);
			int linenum = 1;
			Match lineMatch;
			foreach (string line in lines) {
				lineMatch = fileHeaderExpression.Match (line.Trim ());
				if (lineMatch != null && lineMatch.Success) {
					if (currentFile != null) // Close out previous file region
						currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
						                                        currentFile.BodyRegion.BeginColumn,
						                                        linenum - 1, int.MaxValue);
					if (currentRegion != null) // Close out previous chunk region
						currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
						                                          currentRegion.BodyRegion.BeginColumn,
						                                          linenum - 1, int.MaxValue);
					
					// Create new file region
					currentFile = new DefaultUnresolvedTypeDefinition (string.Empty, string.Empty);
					currentFile.Region = currentFile.BodyRegion = new DomRegion (lastToken (lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
					// doc.TopLevelTypeDefinitions.Add (currentFile);
				} else {
					lineMatch = chunkExpression.Match (line);
					if (lineMatch != null && lineMatch.Success && currentFile != null) {
						if (currentRegion != null) // Close out previous chunk region
							currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
							                                          currentRegion.BodyRegion.BeginColumn,
							                                          linenum - 1, int.MaxValue);
						
						// Create new chunk region
						currentRegion = new DefaultUnresolvedProperty (currentFile, lineMatch.Groups ["chunk"].Value);
						currentRegion.Region = currentRegion.BodyRegion = new DomRegion (currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
						currentFile.Members.Add (currentRegion);
					}
				}
				++linenum;
			}
			
			// Close out trailing regions
			if (currentFile != null)
				currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine,
				                                        currentFile.BodyRegion.BeginColumn, 
				                                        Math.Max (1, linenum - 2), int.MaxValue);
			if (currentRegion != null)
				currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine,
				                                          currentRegion.BodyRegion.BeginColumn, 
				                                          Math.Max (1, linenum - 2), int.MaxValue);
			
			return System.Threading.Tasks.Task.FromResult (doc);
		}
コード例 #17
0
        public override System.Threading.Tasks.Task <ParsedDocument> Parse(ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken)
        {
            ParsedDocument doc = new DefaultParsedDocument(parseOptions.FileName);

            DefaultUnresolvedTypeDefinition currentFile   = null;
            DefaultUnresolvedProperty       currentRegion = null;

            string eol      = Environment.NewLine;
            string content  = parseOptions.Content.Text;
            Match  eolMatch = eolExpression.Match(content);

            if (eolMatch != null && eolMatch.Success)
            {
                eol = eolMatch.Groups ["eol"].Value;
            }

            string[] lines   = content.Split(new string[] { eol }, StringSplitOptions.None);
            int      linenum = 1;
            Match    lineMatch;

            foreach (string line in lines)
            {
                lineMatch = fileHeaderExpression.Match(line.Trim());
                if (lineMatch != null && lineMatch.Success)
                {
                    if (currentFile != null)                     // Close out previous file region
                    {
                        currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.BeginLine,
                                                               currentFile.BodyRegion.BeginColumn,
                                                               linenum - 1, int.MaxValue);
                    }
                    if (currentRegion != null)                     // Close out previous chunk region
                    {
                        currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                                 currentRegion.BodyRegion.BeginColumn,
                                                                 linenum - 1, int.MaxValue);
                    }

                    // Create new file region
                    currentFile        = new DefaultUnresolvedTypeDefinition(string.Empty, string.Empty);
                    currentFile.Region = currentFile.BodyRegion = new DomRegion(lastToken(lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue);
                    // doc.TopLevelTypeDefinitions.Add (currentFile);
                }
                else
                {
                    lineMatch = chunkExpression.Match(line);
                    if (lineMatch != null && lineMatch.Success && currentFile != null)
                    {
                        if (currentRegion != null)                         // Close out previous chunk region
                        {
                            currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                                     currentRegion.BodyRegion.BeginColumn,
                                                                     linenum - 1, int.MaxValue);
                        }

                        // Create new chunk region
                        currentRegion        = new DefaultUnresolvedProperty(currentFile, lineMatch.Groups ["chunk"].Value);
                        currentRegion.Region = currentRegion.BodyRegion = new DomRegion(currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue);
                        currentFile.Members.Add(currentRegion);
                    }
                }
                ++linenum;
            }

            // Close out trailing regions
            if (currentFile != null)
            {
                currentFile.BodyRegion = new DomRegion(currentFile.BodyRegion.BeginLine,
                                                       currentFile.BodyRegion.BeginColumn,
                                                       Math.Max(1, linenum - 2), int.MaxValue);
            }
            if (currentRegion != null)
            {
                currentRegion.BodyRegion = new DomRegion(currentRegion.BodyRegion.BeginLine,
                                                         currentRegion.BodyRegion.BeginColumn,
                                                         Math.Max(1, linenum - 2), int.MaxValue);
            }

            return(System.Threading.Tasks.Task.FromResult(doc));
        }