コード例 #1
0
        public void Parser_Should_Parse_Valid_Sequence(PathToken[] tokens)
        {
            var processedTokens = new List <PathToken>();

            _builder.Setup(v => v.Accept(It.IsAny <PathToken>())).Callback((PathToken token) => processedTokens.Add(token));
            _patParser.Parse(tokens, _builder.Object);

            processedTokens.Should().Equal(tokens,
                                           (t, e) =>
                                           t.Type == e.Type &&
                                           t.Value == e.Value &&
                                           t.InputString == e.InputString &&
                                           t.StartIndex == e.StartIndex &&
                                           t.EndIndex == e.EndIndex);
        }
コード例 #2
0
        void AnalyzePropertyPath(string path)
        {
            var parsedPath = PathParser.Parse(path);

            foreach (var part in parsedPath)
            {
                switch (part.type)
                {
                case SourceValueType.Property:
                    // This is a property reference. This may be directly the name of a property or a reference by
                    // with the type to the property
                    // Simple Property:    "TestProperty"
                    // Property with Type: "(local:DataClass.TestProperty)"

                    var typeName     = part.GetTypeName();
                    var propertyName = part.GetPropertyName();
                    if (!string.IsNullOrWhiteSpace(typeName))
                    {
                        var sig = ResolveType(typeName, out var prefix);
                        if (sig != null && context.Modules.Contains((ModuleDefMD)sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module))
                        {
                            var reference = new BAMLPathTypeReference(xmlnsCtx, sig, part);
                            AddTypeSigReference(sig, reference);
                            break;
                        }
                    }

                    // Reaching this point means that the type reference was either not present or failed to
                    // resolve. In this case every property with the matching name will be flagged so it does not
                    // get renamed.
                    if (properties.TryGetValue(propertyName, out var candidates))
                    {
                        foreach (var property in candidates)
                        {
                            service.SetCanRename(property, false);
                        }
                    }

                    break;

                case SourceValueType.Indexer:
                    // This is the indexer part of a property reference.
                    foreach (var indexerArg in part.paramList)
                    {
                        if (!string.IsNullOrWhiteSpace(indexerArg.parenString))
                        {
                            var sig = ResolveType(indexerArg.parenString, out var prefix);
                            if (sig != null && context.Modules.Contains((ModuleDefMD)sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module))
                            {
                                var reference = new BAMLPathTypeReference(xmlnsCtx, sig, part);
                                AddTypeSigReference(sig, reference);
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }
コード例 #3
0
        public MethodDeclarationSyntax Generate(ILocatedOpenApiElement <OpenApiOperation> operation)
        {
            var propertyNameFormatter = Context.NameFormatterSelector.GetFormatter(NameKind.Property);

            var path = (LocatedOpenApiElement <OpenApiPathItem>)operation.Parent !;

            ExpressionSyntax pathExpression = PathParser.Parse(path.Key).ToInterpolatedStringExpression(
                pathSegment =>
            {
                OpenApiParameter?parameter = operation.Element.Parameters.FirstOrDefault(
                    p => p.Name == pathSegment.Value);

                if (parameter == null)
                {
                    throw new InvalidOperationException(
                        $"Missing path parameter '{pathSegment.Value}' in operation '{operation.Element.OperationId}'.");
                }

                return(InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
                                                                   SerializationNamespace.PathSegmentSerializerInstance,
                                                                   IdentifierName("Serialize")))
                       .AddArgumentListArguments(
                           Argument(SyntaxHelpers.StringLiteral(pathSegment.Value)),
                           Argument(IdentifierName(propertyNameFormatter.Format(pathSegment.Value))),
                           Argument(GetStyleExpression(parameter)),
                           Argument(GetExplodeExpression(parameter))));
            });

            OpenApiParameter[] queryParameters = operation.Element.Parameters
                                                 .Where(p => (p.In ?? ParameterLocation.Query) == ParameterLocation.Query)
                                                 .ToArray();

            if (queryParameters.Length > 0)
            {
                NameSyntax keyValuePairType = WellKnownTypes.System.Collections.Generic.KeyValuePair.Name(
                    PredefinedType(Token(SyntaxKind.StringKeyword)),
                    PredefinedType(Token(SyntaxKind.ObjectKeyword)));

                ExpressionSyntax buildArrayExpression = ArrayCreationExpression(
                    ArrayType(keyValuePairType)
                    .AddRankSpecifiers(ArrayRankSpecifier().AddSizes(OmittedArraySizeExpression())))
                                                        .WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression,
                                                                                               SeparatedList <ExpressionSyntax>(queryParameters
                                                                                                                                .Select(parameter => ObjectCreationExpression(keyValuePairType)
                                                                                                                                        .AddArgumentListArguments(
                                                                                                                                            Argument(SyntaxHelpers.StringLiteral(parameter.Name)),
                                                                                                                                            Argument(IdentifierName(propertyNameFormatter.Format(parameter.Name))))))));

                pathExpression = WellKnownTypes.Yardarm.Client.OperationHelpers.AddQueryParameters(
                    pathExpression, buildArrayExpression);
            }

            return(MethodDeclaration(
                       PredefinedType(Token(SyntaxKind.StringKeyword)),
                       BuildUriMethodName)
                   .AddModifiers(Token(SyntaxKind.PublicKeyword))
                   .WithExpressionBody(ArrowExpressionClause(
                                           pathExpression)));
        }
コード例 #4
0
        public void Parse_InvalidPath_InvalidOperationException()
        {
            // Act/Assert

            Action action = () => PathParser.Parse("/some/{path}/and/{someotherpath");

            action.Should().Throw <InvalidOperationException>();
        }
コード例 #5
0
        public void Parse_Null_ArgumentNullException()
        {
            // Act/Assert

            Action action = () => PathParser.Parse(null);

            action.Should().Throw <ArgumentNullException>();
        }
コード例 #6
0
        public static void SolvePartOne()
        {
            var path = PathParser.Parse(GetInput());
            var map  = new ConstructionMap(path);

            var result = map.CountDoorsToFurthestRoom();

            result.WriteLine("Day 20, Part 1: ");
        }
コード例 #7
0
        public static void SolvePartTwo()
        {
            var path = PathParser.Parse(GetInput());
            var map  = new ConstructionMap(path);

            var result = map.CountRoomsThatNeedAtLeastNumberOfDoorsToPass(1000);

            result.WriteLine("Day 20, Part 2: ");
        }
コード例 #8
0
        public void Parse_EmptyString_Empty()
        {
            // Act

            var result = PathParser.Parse("");

            // Assert

            result.Should().BeEmpty();
        }
コード例 #9
0
ファイル: FastObject.cs プロジェクト: tmnykf/Symbol
    static PathNode[] ParsePath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(PathNode.empty);
        }
        PathParser parser = new PathParser(path);

        System.Collections.Generic.List <PathNode> list = parser.Parse();
        return(list == null ? PathNode.empty : list.ToArray());
    }
コード例 #10
0
        public void Parse_JustText_ExpectedResult()
        {
            // Act

            var result = PathParser.Parse("/some/path");

            // Assert

            result.Should().BeEquivalentTo(new[]
            {
                new PathSegment("/some/path", PathSegmentType.Text)
            });
        }
コード例 #11
0
        public void Parse_HasParameterWithHeader_ExpectedResult()
        {
            // Act

            var result = PathParser.Parse("/some/{path}");

            // Assert

            result.Should().BeEquivalentTo(new[]
            {
                new PathSegment("/some/", PathSegmentType.Text),
                new PathSegment("path", PathSegmentType.Parameter)
            });
        }
コード例 #12
0
        public void Parse_HasParameterWithTrailer_ExpectedResult()
        {
            // Act

            var result = PathParser.Parse("{path}/withtrailer");

            // Assert

            result.Should().BeEquivalentTo(new[]
            {
                new PathSegment("path", PathSegmentType.Parameter),
                new PathSegment("/withtrailer", PathSegmentType.Text),
            });
        }
コード例 #13
0
 public IActionResult Index(string url)
 {
     try
     {
         var viewModel = parser.Parse(url ?? string.Empty);
         return(View(viewModel));
     }
     catch (FolderNotFoundException exception)
     {
         return(NotFound(exception.Message));
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
コード例 #14
0
        public IPathModel Build(string input)
        {
            if (_model != null)
            {
                return(_model);
            }
            var tokens = _lexer.Tokenize(input);

            try
            {
                _parser.Parse(tokens, new ACLTokenAdapter(this));
            } catch (InvalidOperationException exception)
            {
                throw new InvalidPathException(exception.Message, exception);
            }
            return(_model);
        }
コード例 #15
0
        public void Parse_MultipleParameters_ExpectedResult()
        {
            // Act

            var result = PathParser.Parse("/some/{path}/and/{someotherpath}/withtrailer");

            // Assert

            result.Should().BeEquivalentTo(new[]
            {
                new PathSegment("/some/", PathSegmentType.Text),
                new PathSegment("path", PathSegmentType.Parameter),
                new PathSegment("/and/", PathSegmentType.Text),
                new PathSegment("someotherpath", PathSegmentType.Parameter),
                new PathSegment("/withtrailer", PathSegmentType.Text),
            });
        }
コード例 #16
0
        //------------------------------------------------------
        //
        //  Private methods
        //
        //------------------------------------------------------

        // parse the path to figure out what kind of
        // SourceValueInfo we're going to need
        private void PrepareSourceValueInfo(ITypeDescriptorContext typeDescriptorContext)
        {
            PathParser parser = DataBindEngine.CurrentDataBindEngine.PathParser;

            _arySVI = parser.Parse(Path);

            if (_arySVI.Length == 0)
            {
                string detail = parser.Error;
                if (detail == null)
                {
                    detail = Path;
                }
                throw new InvalidOperationException(SR.Get(SRID.PropertyPathSyntaxError, detail));
            }

            ResolvePathParts(typeDescriptorContext);
        }
コード例 #17
0
        // Token: 0x060007B8 RID: 1976 RVA: 0x00017FAC File Offset: 0x000161AC
        private void PrepareSourceValueInfo(ITypeDescriptorContext typeDescriptorContext)
        {
            PathParser pathParser = DataBindEngine.CurrentDataBindEngine.PathParser;

            this._arySVI = pathParser.Parse(this.Path);
            if (this._arySVI.Length == 0)
            {
                string text = pathParser.Error;
                if (text == null)
                {
                    text = this.Path;
                }
                throw new InvalidOperationException(SR.Get("PropertyPathSyntaxError", new object[]
                {
                    text
                }));
            }
            this.ResolvePathParts(typeDescriptorContext);
        }
コード例 #18
0
 public Path?InvalidInputs(string?input) => _parser.Parse(input);
コード例 #19
0
 public static PathName Path(string path)
 {
     return(defaultParser.Parse(path));
 }
コード例 #20
0
 public static PosixPathName PosixPath(string path)
 {
     return((PosixPathName)posixParser.Parse(path));
 }
コード例 #21
0
 public static WindowsPathName WindowsPath(string path)
 {
     return((WindowsPathName)windowsParser.Parse(path));
 }
コード例 #22
0
        public void PathParserTrimsOneTrailingSegmentDelimiter(IEnumerable <string> expectedSegments, string path)
        {
            var pathParser = new PathParser();

            Assert.Equal(expectedSegments, pathParser.Parse(path));
        }