예제 #1
0
        public static MapData LoadFrom(TextReader reader)
        {
            var lexer  = new UdmfLexer(reader);
            var result = UdmfParser.Parse(lexer.Scan());

            return(UdmfSemanticAnalyzer.Process(result));
        }
 public void ShouldParseOldDemoMap()
 {
     using (var stream = File.OpenRead(Path.Combine(TestContext.CurrentContext.TestDirectory, "PigletVersion", "TEXTMAP.txt")))
         using (var textReader = new StreamReader(stream, Encoding.ASCII))
         {
             var sa  = new UdmfSyntaxAnalyzer();
             var map = UdmfParser.Parse(sa.Analyze(new UdmfLexer(textReader)));
         }
 }
예제 #3
0
        public void ShouldHandleParsingMapWithSingleLineComment()
        {
            var map    = @" // Here is a comment
namespace = ""Doom"";";
            var lexer  = new UdmfLexer(map);
            var parser = new UdmfParser(lexer);

            ParseResult result = parser.Parse();

            Assert.That(result.IsSuccess, Is.True);
        }
예제 #4
0
        public void ShouldHandleParsingDemoMap()
        {
            var map = DemoMap.Create();

            using var stream = new MemoryStream();
            map.WriteTo(stream);

            stream.Position = 0;

            using var textReader = new StreamReader(stream, Encoding.ASCII);
            var lexer  = new UnifiedLexer(textReader);
            var result = UdmfParser.Parse(lexer.Scan()).ToArray();
        }
예제 #5
0
        public void ShouldParseEmptyBlock()
        {
            var tokenStream = new Token[]
            {
                new IdentifierToken(FilePosition.StartOfFile, new Identifier("blockName")),
                new OpenBraceToken(FilePosition.StartOfFile),
                new CloseBraceToken(FilePosition.StartOfFile),
            };

            var results = UdmfParser.Parse(tokenStream).ToArray();

            results.Should().HaveCount(1);
            results[0].Should().BeOfType <Block>().Which.Fields.Should().BeEmpty();
        }
예제 #6
0
        public void ShouldRoundTripDemoMap()
        {
            var map = DemoMap.Create();

            using var stream = new MemoryStream();
            map.WriteTo(stream);

            stream.Position = 0;

            using var textReader = new StreamReader(stream, Encoding.ASCII);
            var roundTripped = UdmfSemanticAnalyzer.ReadMapData(UdmfParser.Parse(new UnifiedLexer(textReader).Scan()));

            UdmfComparison.AssertEqual(roundTripped, map);
        }
예제 #7
0
        public void ShouldParseAssignment()
        {
            var tokenStream = new Token[]
            {
                new IdentifierToken(FilePosition.StartOfFile, new Identifier("id")),
                new EqualsToken(FilePosition.StartOfFile),
                new IntegerToken(FilePosition.StartOfFile, 5),
                new SemicolonToken(FilePosition.StartOfFile),
            };

            var results = UdmfParser.Parse(tokenStream).ToArray();

            results.Should().HaveCount(1);
            results[0].Should().BeOfType <Assignment>();
        }
예제 #8
0
        public void ShouldParseAssignment()
        {
            var tokenStream = new Token[]
            {
                new IdentifierToken(FilePosition.StartOfFile(), new Identifier("id")),
                new EqualsToken(FilePosition.StartOfFile()),
                new IntegerToken(FilePosition.StartOfFile(), 5),
                new SemicolonToken(FilePosition.StartOfFile()),
            };

            var results = UdmfParser.Parse(tokenStream).ToArray();

            Assert.That(results, Has.Length.EqualTo(1));
            Assert.That(results[0], Is.TypeOf <Assignment>());
        }
예제 #9
0
        public void ShouldParseBlock()
        {
            var tokenStream = new Token[]
            {
                new IdentifierToken(FilePosition.StartOfFile(), new Identifier("blockName")),
                new OpenBraceToken(FilePosition.StartOfFile()),
                new IdentifierToken(FilePosition.StartOfFile(), new Identifier("id")),
                new EqualsToken(FilePosition.StartOfFile()),
                new IntegerToken(FilePosition.StartOfFile(), 5),
                new SemicolonToken(FilePosition.StartOfFile()),
                new CloseBraceToken(FilePosition.StartOfFile()),
            };

            var results = UdmfParser.Parse(tokenStream).ToArray();

            Assert.That(results, Has.Length.EqualTo(1));
            Assert.That(results[0], Is.TypeOf <Block>());
            Assert.That(((Block)results[0]).Fields, Has.Length.EqualTo(1));
        }
        public void ShouldRoundTripDemoMap()
        {
            var map = DemoMap.Create();

            using (var stream = new MemoryStream())
            {
                map.WriteTo(stream);

                stream.Position = 0;

                using (var textReader = new StreamReader(stream, Encoding.ASCII))
                {
                    var sa           = new UdmfSyntaxAnalyzer();
                    var roundTripped = UdmfParser.Parse(sa.Analyze(new UdmfLexer(textReader)));

                    Assert.That(roundTripped, Is.DeepEqualTo(map));
                }
            }
        }
예제 #11
0
        public void ShouldHandleParsingDemoMap()
        {
            var map = DemoMap.Create();

            using (var stream = new MemoryStream())
            {
                map.WriteTo(stream);

                stream.Position = 0;

                using (var textReader = new StreamReader(stream, Encoding.ASCII))
                {
                    var lexer  = new UdmfLexer(textReader);
                    var parser = new UdmfParser(lexer);

                    ParseResult result = parser.Parse();
                    Assert.That(result.IsSuccess, Is.True);
                }
            }
        }
예제 #12
0
        public void ShouldHandleParsingDemoMap()
        {
            var map = DemoMap.Create();

            using (var fs = File.OpenWrite("text.udmf"))
            {
                map.WriteTo(fs);
            }

            using (var stream = new MemoryStream())
            {
                map.WriteTo(stream);

                stream.Position = 0;

                using (var textReader = new StreamReader(stream, Encoding.ASCII))
                {
                    var lexer  = new UdmfLexer(textReader);
                    var result = UdmfParser.Parse(lexer.Scan()).ToArray();
                }
            }
        }