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))); } }
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); }
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(); }
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(); }
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); }
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>(); }
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>()); }
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)); } } }
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); } } }
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(); } } }