protected override SkriptType TryParse(ParseContext ctx, List <MatchAnnotation> matchAnnotationsHolder) { var litElement = new LiteralPatternElement(""); var startPos = ctx.CurrentPosition; var clone = ctx.Clone(); (int finalPos, SkriptType finalType)? regexMatch = null; foreach (var type in CurrentWorkspace.TypesManager.KnownTypesFromAddons) { clone.CurrentPosition = startPos; litElement.Value = type.FinalTypeName; var result = litElement.Parse(clone); if (!result.IsSuccess) { //The name wasn't matched so try with regex var isRegexSuccess = false; if (type.LoosePatternsRegexps != null) { foreach (var regex in type.LoosePatternsRegexps) { if (isRegexSuccess) { break; } clone.CurrentPosition = startPos; var match = regex.Match(clone.PeekUntilEnd()); if (!match.Success) { continue; } regexMatch = (clone.CurrentPosition + match.Length, type); isRegexSuccess = true; } } continue; } if (CurrentWorkspace.WorkspaceManager.KnownTypesManager.GetTypeByName(type.TypeName) != null) { matchAnnotationsHolder.Add(new MatchAnnotation(MatchAnnotationSeverity.Error, MatchAnnotationCode.CodeUsesInternalType)); } ctx.CurrentPosition = clone.CurrentPosition; return(type); } if (regexMatch != null) { ctx.CurrentPosition = regexMatch.Value.finalPos; return(regexMatch.Value.finalType); } return(null); }
private static void AddSectionEnding() { var sectionNodeAttribute = typeof(T).GetCustomAttribute <SectionNodeAttribute>(); if (sectionNodeAttribute != null) { AbstractSkriptPatternElement section = new LiteralPatternElement(":"); if (sectionNodeAttribute.Optional) { section = new OptionalPatternElement { Element = section }; } ExpressionPattern.Children.Add(section); } }
public void LiteralPatternMatches() { var element = new LiteralPatternElement("abc"); Assert.True(element.Parse("abc").IsSuccess); }
public void LiteralPatternDoesNotMatchWrong() { var element = new LiteralPatternElement("abc"); Assert.False(element.Parse("def").IsSuccess); }
public void LiteralPatternRenderIsCorrect() { var element = new LiteralPatternElement("abc"); Assert.Equal("abc", element.RenderPattern()); }