示例#1
0
        public void Can_resolve_references(String source)
        {
            var parser = new CapnpParser(source);
            var module = parser.Parse();

            module = parser.ProcessParsedSource(module, null);
        }
示例#2
0
        public void Can_parse_schema_capnp()
        {
            var schemaFile = @"..\..\..\Tests\Schema\schema.capnp";

            var schemaContent = File.ReadAllText(schemaFile);

            var parser = new CapnpParser(schemaContent);

            var module = parser.Parse();

            module = parser.ProcessParsedSource(module, s =>
            {
                if (s == "/capnp/c++.capnp")
                {
                    return(@"
                  @0xbdf87d7bb8304e81;
                  $namespace(""capnp::annotations"");
                  annotation namespace(file): Text;
                  annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;
               ");
                }
                throw new Exception("don't understand schema.capnp import " + s);
            });


            Trace.WriteLine(module.ToString());
        }
        private CapnpType _ResolveImport(CapnpImport import)
        {
            if (_GetImportContents == null) throw new Exception("import attempted but no way to resolve it");

             var source = _GetImportContents(import.File);

             var importedType = import.Type;

             var importParser = new CapnpParser(source);
             var parsedSource = importParser.Parse();
             parsedSource = importParser.ProcessParsedSource(parsedSource, _GetImportContents);

             // No type specified, so return the module for later perusal.
             if (importedType == null)
            return parsedSource;

             if (importedType is CapnpReference)
             {
            var @ref = (CapnpReference)importedType;
            return parsedSource.ResolveFullName(@ref.FullName);
             }
             else Debug.Assert(false);

             return importedType;
        }
示例#4
0
        public void Can_do_me_some_parsing(String source)
        {
            var parser = new CapnpParser(source);

            var result = parser.Parse();

            Trace.WriteLine(result);
        }
示例#5
0
        public void Can_handle_entire_capnp_syntax()
        {
            var source = File.ReadAllText("..\\..\\Parser\\FullSyntax.capnp");
            var p      = new CapnpParser(source);
            var m      = p.Parse();

            m = p.ProcessParsedSource(m, null);
        }
示例#6
0
 public void Fail_at_bad_input(String badSource)
 {
     try
     {
         var parser = new CapnpParser(badSource);
         var result = parser.Parse();
         Assert.True(false);
     }
     catch (Xunit.Sdk.AssertException) { throw; }
     catch (Exception e)
     {
         // OK, for now
         Trace.WriteLine(e.Message);
     }
 }
示例#7
0
        public void Detect_bad_syntax(String source)
        {
            var p = new CapnpParser(source);

            try
            {
                p.ProcessParsedSource(p.Parse(), null);
                Assert.True(false);
            }
            catch
            {
                // todo: filter on exception later
                // OK
                // throw;
            }
        }
示例#8
0
        public void Can_resolve_imports(String source, String[] imports)
        {
            Func <String, String> getImport = s =>
            {
                for (var i = 0; i < imports.Length; i++)
                {
                    if (imports[i] == s)
                    {
                        return(imports[i + 1]);
                    }
                }
                throw new Exception("could not find " + s);
            };

            var parser = new CapnpParser(source);
            var phase1 = parser.Parse();

            var phase2 = parser.ProcessParsedSource(phase1, getImport);
        }
示例#9
0
        public void Can_parse_capnp_test_file(String capnpFile)
        {
            var source = File.ReadAllText(capnpFile);
            var p      = new CapnpParser(source);
            var m      = p.Parse();

            m = p.ProcessParsedSource(m, s =>
            {
                if (s == "c++.capnp" || s == "/capnp/c++.capnp")
                {
                    return(@"
                  @0xbdf87d7bb8304e81;
                  $namespace(""capnp::annotations"");
                  annotation namespace(file): Text;
                  annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;
               ");
                }
                throw new Exception("don't understand schema.capnp import " + s);
            });
        }
示例#10
0
 public void Fail_at_bad_input(String badSource)
 {
     try
      {
     var parser = new CapnpParser(badSource);
     var result = parser.Parse();
     Assert.True(false);
      }
      catch (Xunit.Sdk.AssertException) { throw; }
      catch (Exception e)
      {
     // OK, for now
     Trace.WriteLine(e.Message);
      }
 }
示例#11
0
        public void Detect_bad_syntax(String source)
        {
            var p = new CapnpParser(source);

             try
             {
            p.ProcessParsedSource(p.Parse(), null);
            Assert.True(false);
             }
             catch
             {
            // todo: filter on exception later
            // OK
            // throw;
             }
        }
示例#12
0
 public void Can_resolve_references(String source)
 {
     var parser = new CapnpParser(source);
      var module = parser.Parse();
      module = parser.ProcessParsedSource(module, null);
 }
示例#13
0
        public void Can_resolve_imports(String source, String[] imports)
        {
            Func<String, String> getImport = s =>
             {
            for (var i = 0; i < imports.Length; i++)
               if (imports[i] == s) return imports[i + 1];
            throw new Exception("could not find " + s);
             };

             var parser = new CapnpParser(source);
             var phase1 = parser.Parse();

             var phase2 = parser.ProcessParsedSource(phase1, getImport);
        }
示例#14
0
        public void Can_parse_schema_capnp()
        {
            var schemaFile = @"..\..\..\Tests\Schema\schema.capnp";

             var schemaContent = File.ReadAllText(schemaFile);

             var parser = new CapnpParser(schemaContent);

             var module = parser.Parse();
             module = parser.ProcessParsedSource(module, s =>
             {
            if (s == "/capnp/c++.capnp")
               return @"
                  @0xbdf87d7bb8304e81;
                  $namespace(""capnp::annotations"");
                  annotation namespace(file): Text;
                  annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;
               ";
            throw new Exception("don't understand schema.capnp import " + s);
             });

             Trace.WriteLine(module.ToString());
        }
示例#15
0
 public void Can_parse_capnp_test_file(String capnpFile)
 {
     var source = File.ReadAllText(capnpFile);
      var p = new CapnpParser(source);
      var m = p.Parse();
      m = p.ProcessParsedSource(m, s =>
      {
     if (s == "c++.capnp" || s == "/capnp/c++.capnp")
        return @"
           @0xbdf87d7bb8304e81;
           $namespace(""capnp::annotations"");
           annotation namespace(file): Text;
           annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text;
        ";
     throw new Exception("don't understand schema.capnp import " + s);
      });
 }
示例#16
0
 public void Can_handle_entire_capnp_syntax()
 {
     var source = File.ReadAllText("..\\..\\Parser\\FullSyntax.capnp");
      var p = new CapnpParser(source);
      var m = p.Parse();
      m = p.ProcessParsedSource(m, null);
 }
示例#17
0
        public void Can_do_me_some_parsing(String source)
        {
            var parser = new CapnpParser(source);

             var result = parser.Parse();

             Trace.WriteLine(result);
        }