public void DocTypeCapture() { var parser = new TestXmlParser(CreateRootState(), true); parser.Parse(@" <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""DTD/xhtml1-strict.dtd"" [ <!-- foo --> <!bar #baz> ]> <doc><foo/></doc>"); parser.AssertEmpty(); XDocument doc = (XDocument)parser.Nodes.Peek(); Assert.IsTrue(doc.FirstChild is XDocType); XDocType dt = (XDocType)doc.FirstChild; Assert.AreEqual("html", dt.RootElement.FullName); Assert.AreEqual("-//W3C//DTD XHTML 1.0 Strict//EN", dt.PublicFpi); Assert.AreEqual("DTD/xhtml1-strict.dtd", dt.Uri); Assert.AreEqual(dt.InternalDeclarationRegion.Begin.Line, 4); Assert.AreEqual(dt.InternalDeclarationRegion.End.Line, 7); parser.AssertNoErrors(); }
void CreateDocType() { DocType = new XDocType(MonoDevelop.Ide.Editor.DocumentLocation.Empty); var matches = DocTypeRegex.Match(razorDocument.PageInfo.DocType); if (matches.Success) { DocType.PublicFpi = matches.Groups ["fpi"].Value; DocType.Uri = matches.Groups ["uri"].Value; } }
protected override void ShallowCopyFrom(XObject copyFrom) { base.ShallowCopyFrom(copyFrom); XDocType copyFromDT = (XDocType)copyFrom; //immutable types RootElement = copyFromDT.RootElement; PublicFpi = copyFromDT.PublicFpi; InternalDeclarationRegion = copyFromDT.InternalDeclarationRegion; Uri = copyFromDT.Uri; }
void HandleDocType(XDocType docType) { DocType = "<!DOCTYPE html"; if (!string.IsNullOrEmpty(docType.PublicFpi)) { DocType += " \"" + docType.PublicFpi + "\""; } if (!string.IsNullOrEmpty(docType.Uri)) { DocType += " \"" + docType.Uri + "\""; } DocType += ">"; }
protected override Task <ICompletionDataList> HandleCodeCompletion( CodeCompletionContext completionContext, bool forced, CancellationToken token) { // completionChar may be a space even if the current char isn't, when ctrl-space is fired t char currentChar = completionContext.TriggerOffset < 1? ' ' : Editor.GetCharAt(completionContext.TriggerOffset - 1); //char previousChar = completionContext.TriggerOffset < 2? ' ' : buf.GetCharAt (completionContext.TriggerOffset - 2); //directive names if (Tracker.Engine.CurrentState is WebFormsDirectiveState) { var directive = Tracker.Engine.Nodes.Peek() as WebFormsDirective; if (HasDoc && directive != null && directive.Region.BeginLine == completionContext.TriggerLine && directive.Region.BeginColumn + 3 == completionContext.TriggerLineOffset) { return(Task.FromResult((ICompletionDataList)WebFormsDirectiveCompletion.GetDirectives(aspDoc.Type))); } return(null); } if (Tracker.Engine.CurrentState is XmlNameState && Tracker.Engine.CurrentState.Parent is WebFormsDirectiveState) { var directive = Tracker.Engine.Nodes.Peek() as WebFormsDirective; if (HasDoc && directive != null && directive.Region.BeginLine == completionContext.TriggerLine && directive.Region.BeginColumn + 4 == completionContext.TriggerLineOffset && char.IsLetter(currentChar)) { completionContext.TriggerWordLength = 1; completionContext.TriggerOffset -= 1; return(Task.FromResult((ICompletionDataList)WebFormsDirectiveCompletion.GetDirectives(aspDoc.Type))); } return(null); } bool isAspExprState = Tracker.Engine.CurrentState is WebFormsExpressionState; //non-xml tag completion if (currentChar == '<' && !(isAspExprState || Tracker.Engine.CurrentState is XmlRootState)) { var list = new CompletionDataList(); AddAspBeginExpressions(list); return(Task.FromResult((ICompletionDataList)list)); } if (!HasDoc || aspDoc.Info.DocType == null) { //FIXME: get doctype from master page DocType = null; } else { DocType = new XDocType(DocumentLocation.Empty); var matches = DocTypeRegex.Match(aspDoc.Info.DocType); DocType.PublicFpi = matches.Groups["fpi"].Value; DocType.Uri = matches.Groups["uri"].Value; } if (Tracker.Engine.CurrentState is HtmlScriptBodyState) { var el = Tracker.Engine.Nodes.Peek() as XElement; if (el != null) { if (el.IsRunatServer()) { if (documentBuilder != null) { // TODO: C# completion } } /* * else { * att = GetHtmlAtt (el, "language"); * if (att == null || "javascript".Equals (att.Value, StringComparison.OrdinalIgnoreCase)) { * att = GetHtmlAtt (el, "type"); * if (att == null || "text/javascript".Equals (att.Value, StringComparison.OrdinalIgnoreCase)) { * // TODO: JS completion * } * } * }*/ } } return(base.HandleCodeCompletion(completionContext, forced, token)); }
public override State PushChar (char c, IParseContext context, ref string rollback) { XDocType doc = context.Nodes.Peek () as XDocType; if (doc == null) { doc = new XDocType (context.LocationMinus ("<!DOCTYPE".Length + 1)); context.Nodes.Push (doc); } if (!doc.RootElement.IsValid) { if (XmlChar.IsWhitespace (c)) return null; else if (XmlChar.IsFirstNameChar (c)) { rollback = ""; return nameState; } } else if (doc.PublicFpi == null) { if (context.StateTag == 0) { if (c == 's' || c == 'S') { context.StateTag = 1; return null; } else if (c == 'p' || c == 'P') { context.StateTag = -1; return null; } if (XmlChar.IsWhitespace (c)) { return null; } } else if (Math.Abs (context.StateTag) < 6) { if (context.StateTag > 0) { if ("YSTEM"[context.StateTag - 1] == c || "ystem"[context.StateTag - 1] == c) { context.StateTag++; if (context.StateTag == 6) { context.StateTag = 0; doc.PublicFpi = ""; } return null; } } else { int absState = Math.Abs (context.StateTag) - 1; if ("UBLIC"[absState] == c || "ublic"[absState] == c) { context.StateTag--; return null; } } } else { if (context.KeywordBuilder.Length == 0) { if (XmlChar.IsWhitespace (c)) return null; else if (c == '"') { context.KeywordBuilder.Append (c); return null; } } else { if (c == '"') { context.KeywordBuilder.Remove (0,1); doc.PublicFpi = context.KeywordBuilder.ToString (); context.KeywordBuilder.Length = 0; context.StateTag = 0; } else { context.KeywordBuilder.Append (c); } return null; } } } else if (doc.Uri == null) { if (context.KeywordBuilder.Length == 0) { if (XmlChar.IsWhitespace (c)) return null; else if (c == '"') { context.KeywordBuilder.Append (c); return null; } } else { if (c == '"') { context.KeywordBuilder.Remove (0,1); doc.Uri = context.KeywordBuilder.ToString (); context.KeywordBuilder.Length = 0; } else { context.KeywordBuilder.Append (c); } return null; } } else if (doc.InternalDeclarationRegion.End.Line <= 0) { if (XmlChar.IsWhitespace (c)) return null; switch (context.StateTag) { case 0: if (c == '[') { doc.InternalDeclarationRegion = new DomRegion (context.Location, DomLocation.Empty); context.StateTag = 1; return null; } break; case 1: if (c == '<') { context.StateTag = 2; return null; } else if (c == ']') { context.StateTag = 0; doc.InternalDeclarationRegion = new DomRegion (doc.InternalDeclarationRegion.Start, context.Location); return null; } break; case 2: if (c == '>') { context.StateTag = 1; } return null; default: throw new InvalidOperationException (); } } doc = (XDocType)context.Nodes.Pop (); if (c == '<') { rollback = string.Empty; context.LogError ("Doctype ended prematurely."); } else if (c != '>') { context.LogError ("Unexpected character '" + c +"' in doctype."); } if (context.BuildTree) { doc.End (context.Location); ((XContainer) context.Nodes.Peek ()).AddChildNode (doc); } return Parent; }
public override XmlParserState PushChar(char c, IXmlParserContext context, ref string rollback) { var doc = context.Nodes.Peek() as XDocType; if (doc == null) { doc = new XDocType(context.LocationMinus("<!DOCTYPE".Length + 1)); context.Nodes.Push(doc); } if (!doc.RootElement.IsValid) { if (XmlChar.IsWhitespace(c)) { return(null); } else if (XmlChar.IsFirstNameChar(c)) { rollback = ""; return(nameState); } } else if (doc.PublicFpi == null) { if (context.StateTag == 0) { if (c == 's' || c == 'S') { context.StateTag = 1; return(null); } else if (c == 'p' || c == 'P') { context.StateTag = -1; return(null); } if (XmlChar.IsWhitespace(c)) { return(null); } } else if (Math.Abs(context.StateTag) < 6) { if (context.StateTag > 0) { if ("YSTEM"[context.StateTag - 1] == c || "ystem"[context.StateTag - 1] == c) { context.StateTag++; if (context.StateTag == 6) { context.StateTag = 0; doc.PublicFpi = ""; } return(null); } } else { int absState = Math.Abs(context.StateTag) - 1; if ("UBLIC"[absState] == c || "ublic"[absState] == c) { context.StateTag--; return(null); } } } else { if (context.KeywordBuilder.Length == 0) { if (XmlChar.IsWhitespace(c)) { return(null); } else if (c == '"') { context.KeywordBuilder.Append(c); return(null); } } else { if (c == '"') { context.KeywordBuilder.Remove(0, 1); doc.PublicFpi = context.KeywordBuilder.ToString(); context.KeywordBuilder.Length = 0; context.StateTag = 0; } else { context.KeywordBuilder.Append(c); } return(null); } } } else if (doc.Uri == null) { if (context.KeywordBuilder.Length == 0) { if (XmlChar.IsWhitespace(c)) { return(null); } else if (c == '"') { context.KeywordBuilder.Append(c); return(null); } } else { if (c == '"') { context.KeywordBuilder.Remove(0, 1); doc.Uri = context.KeywordBuilder.ToString(); context.KeywordBuilder.Length = 0; } else { context.KeywordBuilder.Append(c); } return(null); } } else if (doc.InternalDeclarationRegion.EndLine <= 0) { if (XmlChar.IsWhitespace(c)) { return(null); } switch (context.StateTag) { case 0: if (c == '[') { doc.InternalDeclarationRegion = new DomRegion(context.Location, TextLocation.Empty); context.StateTag = 1; return(null); } break; case 1: if (c == '<') { context.StateTag = 2; return(null); } else if (c == ']') { context.StateTag = 0; doc.InternalDeclarationRegion = new DomRegion(doc.InternalDeclarationRegion.Begin, context.Location); return(null); } break; case 2: if (c == '>') { context.StateTag = 1; } return(null); default: throw new InvalidOperationException(); } } doc = (XDocType)context.Nodes.Pop(); if (c == '<') { rollback = string.Empty; context.LogError("Doctype ended prematurely."); } else if (c != '>') { context.LogError("Unexpected character '" + c + "' in doctype."); } if (context.BuildTree) { doc.End(context.Location); ((XContainer)context.Nodes.Peek()).AddChildNode(doc); } return(Parent); }
void HandleDocType (XDocType docType) { DocType = "<!DOCTYPE html"; if (!string.IsNullOrEmpty (docType.PublicFpi)) DocType += " \"" + docType.PublicFpi + "\""; if (!string.IsNullOrEmpty (docType.Uri)) DocType += " \"" + docType.Uri + "\""; DocType += ">"; }