Пример #1
0
        private void ParseMessagesInternal()
        {
            var packageDependencyCollector = new PackageDependencyCollector(new [] { Package.Name });
            var typeDependencyCollector    = new TypeDependencyCollector(new [] { Package.Name });

            var collectors = new RosMessageVisitorListenerCollection(new IRosMessageVisitorListener[]
                                                                     { packageDependencyCollector, typeDependencyCollector });

            var messages = new List <KeyValuePair <RosTypeInfo, MessageDescriptor> >();
            var actions  = new List <KeyValuePair <RosTypeInfo, ActionDescriptor> >();
            var services = new List <KeyValuePair <RosTypeInfo, ServiceDescriptor> >();

            foreach (var messageFile in Package.Messages)
            {
                using (var fileStream = File.OpenRead(messageFile.FullName))
                {
                    var rosType = RosTypeInfo.CreateRosType(Package.Name, messageFile.NameWithoutExtension());

                    switch (messageFile.GetRosMessageType())
                    {
                    case RosMessageType.Message:
                        var messageParser     = new RobSharper.Ros.MessageParser.MessageParser(fileStream);
                        var messageDescriptor = messageParser.Parse(collectors);

                        messages.Add(
                            new KeyValuePair <RosTypeInfo, MessageDescriptor>(rosType, messageDescriptor));
                        break;

                    case RosMessageType.Service:
                        var serviceParser     = new ServiceParser(fileStream);
                        var serviceDescriptor = serviceParser.Parse(collectors);

                        services.Add(
                            new KeyValuePair <RosTypeInfo, ServiceDescriptor>(rosType, serviceDescriptor));
                        break;

                    case RosMessageType.Action:
                        var actionParser     = new ActionParser(fileStream);
                        var actionDescriptor = actionParser.Parse(collectors);

                        actions.Add(
                            new KeyValuePair <RosTypeInfo, ActionDescriptor>(rosType, actionDescriptor));
                        break;
                    }
                }
            }

            // Add actionlib dependency
            if (actions.Any() && !packageDependencyCollector.Dependencies.Contains("actionlib_msgs"))
            {
                packageDependencyCollector.Dependencies.Add("actionlib_msgs");
            }

            _packageDependencies      = packageDependencyCollector.Dependencies;
            _externalTypeDependencies = typeDependencyCollector.Dependencies;
            _messages = messages;
            _actions  = actions;
            _services = services;
        }
Пример #2
0
        public void ParseFileStream(string filePath)
        {
            MessageDescriptor descriptor;

            using (var file = File.OpenRead(filePath))
            {
                var parser = new RobSharper.Ros.MessageParser.MessageParser(file);
                descriptor = parser.Parse();
            }
        }
Пример #3
0
        public void Can_parse_empty_message()
        {
            var message = string.Empty;

            var actual = new RobSharper.Ros.MessageParser.MessageParser(message).Parse();

            Assert.NotNull(actual);
            Assert.True(actual.IsEmpty);

            Assert.Empty(actual.Comments);
            Assert.Empty(actual.Constants);
            Assert.Empty(actual.Fields);
        }
Пример #4
0
        public void Can_parse_simple_message()
        {
            var message = "int8 fooo";

            var actual = new RobSharper.Ros.MessageParser.MessageParser(message).Parse();;

            Assert.NotNull(actual);
            Assert.Empty(actual.Comments);
            Assert.Empty(actual.Constants);

            Assert.Single(actual.Fields);

            var field       = actual.Fields.First();
            var typeMapping = BuiltInTypeMapping.Create(field.TypeInfo);

            Assert.Equal(BuiltInTypeMapping.Int8, typeMapping);
            Assert.Equal("fooo", field.Identifier);
        }
Пример #5
0
        public void Can_load_msg_file(TestMessage file)
        {
            var actual = new RobSharper.Ros.MessageParser.MessageParser(file.Content.Value).Parse();

            Assert.NotNull(actual);
        }
Пример #6
0
 public void ParseFileFContent(string filePath)
 {
     var parser     = new RobSharper.Ros.MessageParser.MessageParser(File.ReadAllText(filePath));
     var descriptor = parser.Parse();
 }