public void AssertResource(string name) { var parser = new AnnotationParser(); parser.RegisterAnnotation <AssertInspectionAnnotation>(); SkriptFile file = null; var host = new InspectionDelegatingHost((uri, list) => { foreach (var diagnostic in list) { // ReSharper disable AccessToModifiedClosure Debug.Assert(file != null, nameof(file) + " != null"); var node = file.Nodes[diagnostic.Range.Start.Line]; //TODO: Allow multiple annotations to a single node by parsing the comments directly above. var comment = node.RawComment.TrimStart('#').Trim(); if (!comment.StartsWith("@")) { continue; } var annotation = parser.TryParse(comment); switch (annotation) { case AssertInspectionAnnotation assertInspectionAnnotation: Assert.Equal(assertInspectionAnnotation.InspectionType, diagnostic.Code); break; default: throw new ArgumentOutOfRangeException(nameof(annotation)); } // ReSharper restore AccessToModifiedClosure } }); WorkspaceManager.CurrentHost = host; var current = WorkspaceManager.CurrentWorkspace; var code = ReadResource(name); file = new SkriptFile(new Uri($"memory://{name}")); file.HandleChange(new TextDocumentContentChangeEvent { Text = code }); file.PrepareNodes(); parser.UnregisterAnnotation <AssertInspectionAnnotation>(); }
public void SetXmlParametres(string xmlPath) { AnnotationParser annotation = new AnnotationParser(xmlPath); Name = annotation.Name; Defect = annotation.Defects.ToString(); Background = annotation.Parametres[0]; Crack = annotation.Parametres[1]; Spallation = annotation.Parametres[2]; Efflorescence = annotation.Parametres[3]; ExposedRebar = annotation.Parametres[4]; CorrosionStain = annotation.Parametres[5]; }
public void EmptyAnnotationParserWorks() { var code = "@empty"; var parser = new AnnotationParser(); parser.RegisterAnnotation <EmptyAnnotation>(); var annotation = parser.TryParse(code); Assert.NotNull(annotation); Assert.IsType <EmptyAnnotation>(annotation); parser.UnregisterAnnotation <EmptyAnnotation>(); }
public News GetSingle(object id) { var path = GlobalizationFileFinder.GetFilePathById(_path, id.ToString(), _lang); var md = File.ReadAllText(path); var result = AnnotationParser.Parse(md); return(new News { Id = id.ToString(), Title = result.Annotations.ContainsKey("Title") ? result.Annotations["Title"] : null, PublishedAt = result.Annotations.ContainsKey("Published at") ? Convert.ToDateTime(result.Annotations["Published at"]) : DateTime.MinValue, IsPinned = result.Annotations.ContainsKey("Pinned") ? Convert.ToBoolean(result.Annotations["Pinned"]) : false, Content = result.PlainMarkdown }); }
private static RubyParser.TokenVisitor CreateTokenVisitor(FormattedTextBuffer buffer) { var visitor = new RubyParser.TokenVisitor { OnNormal = text => { var tokens2 = AnnotationParser.Parse(text); foreach (var token2 in tokens2) { token2.Accept(new AnnotationParser.TokenVisitor { OnBody = bodyText => buffer.Append(bodyText), OnPlaceholder = () => buffer.Append(AozoraBunko.SpecialCharacters.ExternalCharacterPlaceholder), OnAnnotation = annotationText => { //見出し var headingText = HeadingParser.Parse(annotationText); if (headingText != null) { //TODO: 見出しレベル buffer.HeadingTitle = headingText; return; } //圏点 var emphasysDottedText = EmphasysDotsParser.Parse(annotationText); if (emphasysDottedText != null) { buffer.EmphasysDot(buffer.Length - emphasysDottedText.Length, buffer.Length); return; } //TODO: その他の注記 } }); } ; }, OnRuby = (baseText, rubyText) => { buffer.Append(baseText); buffer.Ruby(buffer.Length - baseText.Length, buffer.Length, rubyText); } }; return(visitor); }
public void OneStringParserWorks() { var code = new[] { "@onestring ", "@1str " }; var args = "one argument parameter"; var parser = new AnnotationParser(); parser.RegisterAnnotation <OneStringAnnotation>(); foreach (var prefix in code) { var annotation = parser.TryParse(prefix + args); Assert.NotNull(annotation); Assert.IsType <OneStringAnnotation>(annotation); Assert.Equal(args, ((OneStringAnnotation)annotation).Value); } parser.UnregisterAnnotation <EmptyAnnotation>(); }
internal virtual Annotation[][] ParseParameterAnnotations(sbyte[] parameterAnnotations) { return(AnnotationParser.parseParameterAnnotations(parameterAnnotations, sun.misc.SharedSecrets.JavaLangAccess.getConstantPool(DeclaringClass), DeclaringClass)); }