public void ParsesFileWithTheLot() { var tokens = new DjinniLexer(); var productions = new Parser(); var file = new FileParser(); var sections = file.Consume( productions.Consume( tokens.Consume( TestInputStrings.DirectiveAndTwoTypes))); CollectionAssert.AreEqual( new[] { FileSection.Directives, FileSection.Type, FileSection.Type }, sections.Select(s => s.Kind).Where(k => k != FileSection.Empty)); }
public void ParsesSequenceOfThings() { var input = @"typename = interface +x +y { methodname(arg: type): type; const property: string = ""value""; }"; var lexer = new DjinniLexer(); var parser = new Parser(); var parsed = parser.Consume(lexer.Consume(input)); CollectionAssert.AreEqual( new[] { ProductionKind.TypeDeclaration, ProductionKind.OpenBlock, ProductionKind.MemberDeclaration, ProductionKind.MemberDeclaration, ProductionKind.CloseBlock }, parsed.Select(t => t.Kind).Where(k => k != ProductionKind.Null)); }
public void ParsesInvalidMemberMissingSemi() { var input = @"@extern ""XYZ"" typename = struct { invalid }"; var lexer = new DjinniLexer(); var parser = new Parser(); var parsed = parser.Consume(lexer.Consume(input)); CollectionAssert.AreEqual( new[] { ProductionKind.Directive, ProductionKind.TypeDeclaration, ProductionKind.OpenBlock, ProductionKind.MemberDeclaration, ProductionKind.CloseBlock }, parsed.Select(t => t.Kind).Where(k => k != ProductionKind.Null)); }