Beispiel #1
0
        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);
            }
        }
Beispiel #3
0
        public void LiteralPatternMatches()
        {
            var element = new LiteralPatternElement("abc");

            Assert.True(element.Parse("abc").IsSuccess);
        }
Beispiel #4
0
        public void LiteralPatternDoesNotMatchWrong()
        {
            var element = new LiteralPatternElement("abc");

            Assert.False(element.Parse("def").IsSuccess);
        }
Beispiel #5
0
        public void LiteralPatternRenderIsCorrect()
        {
            var element = new LiteralPatternElement("abc");

            Assert.Equal("abc", element.RenderPattern());
        }