コード例 #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);
        }
コード例 #2
0
        public void LiteralPatternMatches()
        {
            var element = new LiteralPatternElement("abc");

            Assert.True(element.Parse("abc").IsSuccess);
        }
コード例 #3
0
        public void LiteralPatternDoesNotMatchWrong()
        {
            var element = new LiteralPatternElement("abc");

            Assert.False(element.Parse("def").IsSuccess);
        }