Пример #1
0
 public static void Main(string[] args)
 {
     using (FileStream fs = new FileStream("../../../../Typemaker.Compiler/test.tm", FileMode.Open, FileAccess.Read))
     {
         var input      = new AntlrInputStream(fs);
         var lexer      = new TypemakerLexer(input);
         var tokens     = lexer.GetAllTokens();
         var tokenNames = String.Join(" ", tokens.Select(x => lexer.Vocabulary.GetDisplayName(x.Type)));
         Console.WriteLine(tokenNames);
         Console.ReadKey();
     }
 }
 static void SourceMatchTokens(string source, List <int> expectedTokens)
 {
     using (var ss = new StringReader(source))
     {
         var input              = new AntlrInputStream(ss);
         var lexer              = new TypemakerLexer(input);
         var tokenInterfaces    = lexer.GetAllTokens();
         var actualTokens       = tokenInterfaces.Select(x => x.Type).ToList();
         var translatedExpected = expectedTokens.Select(x => lexer.Vocabulary.GetSymbolicName(x)).ToList();
         var translatedActual   = actualTokens.Select(x => lexer.Vocabulary.GetSymbolicName(x)).ToList();
         Assert.Equal(expectedTokens.Count, actualTokens.Count);
         for (var I = 0; I < expectedTokens.Count; ++I)
         {
             Assert.True(actualTokens[I] == expectedTokens[I], "Expected " + translatedExpected[I] + " got " + translatedActual[I]);
         }
     }
 }