Пример #1
0
        private ListObjectKeyValueNode GetListObjectKeyValue(string key)
        {
            var listObjectKeyValue = new ListObjectKeyValueNode(key);

            while (true)
            {
                string line = GetNextLine().Trim().TrimEnd(',');
                if (line == "]")
                {
                    break;
                }

                var results = RegexDecisionTree.GetEntryType(line);

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (results.Type)
                {
                case EntryType.OpenBraces:
                    listObjectKeyValue.Add(GetObjectValue());
                    break;

                case EntryType.DigitKey:
                    listObjectKeyValue.Add(GetDigitKey(line));
                    break;

                default:
                    throw new InvalidDataException($"Unhandled entry type encountered: {results.Type}");
                }
            }

            return(listObjectKeyValue);
        }
Пример #2
0
        public void GetEntryType_ReferenceStringKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                       'transcript' => $VAR1->{'22'}[0],");

            Assert.Equal(EntryType.ReferenceStringKeyValue, results.Type);
            Assert.Equal("transcript", results.Key);
            Assert.Equal("$VAR1->{'22'}[0]", results.Value);
        }
Пример #3
0
        public void GetEntryType_EmptyValueKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                'cell_types' => {},");

            Assert.Equal(EntryType.EmptyValueKeyValue, results.Type);
            Assert.Equal("cell_types", results.Key);
            Assert.Null(results.Value);
        }
Пример #4
0
        public void GetEntryType_EmptyListKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                                    'seq_edits' => [],");

            Assert.Equal(EntryType.EmptyListKeyValue, results.Type);
            Assert.Equal("seq_edits", results.Key);
            Assert.Null(results.Value);
        }
Пример #5
0
        public void GetEntryType_RootObjectKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("$VAR1 = {");

            Assert.Equal(EntryType.RootObjectKeyValue, results.Type);
            Assert.Equal("$VAR1", results.Key);
            Assert.Null(results.Value);
        }
Пример #6
0
        public void GetEntryType_DigitKey()
        {
            var results = RegexDecisionTree.GetEntryType("                                                                            0,");

            Assert.Equal(EntryType.DigitKey, results.Type);
            Assert.Equal("0", results.Key);
            Assert.Null(results.Value);
        }
Пример #7
0
 public void GetEntryType_ThrowsNotImplementedException(string s)
 {
     Assert.Throws <NotImplementedException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var results = RegexDecisionTree.GetEntryType(s);
     });
 }
Пример #8
0
        public void GetEntryType_UndefKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                                                           'adaptor' => undef,");

            Assert.Equal(EntryType.UndefKeyValue, results.Type);
            Assert.Equal("adaptor", results.Key);
            Assert.Null(results.Value);
        }
Пример #9
0
        public void GetEntryType_ObjectKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                                                           'next' => bless( {");

            Assert.Equal(EntryType.ObjectKeyValue, results.Type);
            Assert.Equal("next", results.Key);
            Assert.Null(results.Value);
        }
Пример #10
0
        public void GetEntryType_EndBracesWithDataType()
        {
            var results = RegexDecisionTree.GetEntryType("                                                            }, 'Bio::EnsEMBL::Exon' ),");

            Assert.Equal(EntryType.EndBracesWithDataType, results.Type);
            Assert.Equal("Bio::EnsEMBL::Exon", results.Key);
            Assert.Null(results.Value);
        }
Пример #11
0
        public void GetEntryType_EndBraces()
        {
            var results = RegexDecisionTree.GetEntryType("                                                                },");

            Assert.Equal(EntryType.EndBraces, results.Type);
            Assert.Null(results.Key);
            Assert.Null(results.Value);
        }
Пример #12
0
        public void GetEntryType_DigitKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                                                              'phase' => -1,");

            Assert.Equal(EntryType.DigitKeyValue, results.Type);
            Assert.Equal("phase", results.Key);
            Assert.Equal("-1", results.Value);
        }
Пример #13
0
        public void GetEntryType_StringKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("                            '_ccds' => 'CCDS44137.1',");

            Assert.Equal(EntryType.StringKeyValue, results.Type);
            Assert.Equal("_ccds", results.Key);
            Assert.Equal("CCDS44137.1", results.Value);
        }
Пример #14
0
        public void GetEntryType_OpenBraces()
        {
            var results = RegexDecisionTree.GetEntryType("                   bless( {");

            Assert.Equal(EntryType.OpenBraces, results.Type);
            Assert.Null(results.Key);
            Assert.Null(results.Value);
        }
Пример #15
0
        public void GetEntryType_ListObjectKeyValue()
        {
            var results = RegexDecisionTree.GetEntryType("          '1' => [");

            Assert.Equal(EntryType.ListObjectKeyValue, results.Type);
            Assert.Equal("1", results.Key);
            Assert.Null(results.Value);
        }
Пример #16
0
        private ObjectValueNode GetObjectValue()
        {
            var type  = "(unknown)";
            var nodes = new List <IImportNode>();

            while (true)
            {
                string line    = GetNextLine();
                var    results = RegexDecisionTree.GetEntryType(line);

                if (results.Type == EntryType.EndBraces || results.Type == EntryType.EndBracesWithDataType)
                {
                    if (results.Type == EntryType.EndBracesWithDataType)
                    {
                        type = results.Key;
                    }
                    break;
                }

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (results.Type)
                {
                case EntryType.ObjectKeyValue:
                    nodes.Add(new ObjectKeyValueNode(results.Key, GetObjectValue()));
                    break;

                case EntryType.ListObjectKeyValue:
                    nodes.Add(GetListObjectKeyValue(results.Key));
                    break;

                case EntryType.DigitKeyValue:
                case EntryType.StringKeyValue:
                case EntryType.ReferenceStringKeyValue:
                    nodes.Add(new StringKeyValueNode(results.Key, results.Value));
                    break;

                case EntryType.UndefKeyValue:
                case EntryType.EmptyListKeyValue:
                case EntryType.EmptyValueKeyValue:
                    nodes.Add(new StringKeyValueNode(results.Key, null));
                    break;

                case EntryType.MultiLineKeyValue:
                    nodes.Add(GetMultiLineKeyValue(results.Key, results.Value));
                    break;

                default:
                    throw new InvalidDataException($"Unhandled entry type encountered in GetObjectValue: {results.Type}: [{line}]");
                }
            }

            return(new ObjectValueNode(type, nodes));
        }
Пример #17
0
        public ObjectKeyValueNode GetRootNode()
        {
            string line = GetNextLine();

            if (line == null)
            {
                throw new InvalidDataException("Expected a root object node, but no data was found.");
            }

            var results = RegexDecisionTree.GetEntryType(line);

            if (results.Type != EntryType.RootObjectKeyValue)
            {
                throw new InvalidDataException($"Expected a root object node, but found a {results.Type} node.");
            }

            return(new ObjectKeyValueNode(results.Key, GetObjectValue()));
        }