// [Fact] // public void DentedOnly() // { // var source = @" //namespace Foo // type Bar // func Baz"; // var expected = @" //►namespace Foo // ►type Bar // ►func Baz◄◄◄"; // AssertSourceEqualsTokenized(expected, source); // } // [Fact] // public void InsensitiveOnlyMultiLine() // { // var source = @"namespace Foo { // type Bar { // func Baz {} // } //}"; // AssertSourceEqualsTokenized(source, source); // } //[Fact] //public void InsensitiveOnlySingleLine() //{ // var source = "namespace Foo { type Bar { func Baz {} } }"; // AssertSourceEqualsTokenized(source, source); //} //[Fact] //public void SingleLineOnly() //{ // var source = "namespace Foo -> type Bar -> func Baz -> a = b"; // var expected = "namespace Foo -> type Bar -> func Baz -> a = b<ExpressionBodyEnd><ExpressionBodyEnd><ExpressionBodyEnd>"; // AssertSourceEqualsTokenized(expected, source); //} //[Fact] //public void SingleLineInsideInsensitiveOnly() //{ // var source = "namespace Foo { type Bar -> func Baz {} }"; // var expected = "namespace Foo { type Bar -> func Baz {} <ExpressionBodyEnd>}"; // AssertSourceEqualsTokenized(expected, source); //} //[Fact] //public void DentedInsideTwoSingleLines() //{ // var source = "namespace Foo -> type Bar -> func Baz\n\ta = b"; // var expected = "namespace Foo -> type Bar -> func Baz\n\t<Indent>a = b<Dedent><ExpressionBodyEnd><ExpressionBodyEnd>"; // AssertSourceEqualsTokenized(expected, source); //} //[Fact] //public void SingleLineInsideDentedInsideSingleLine() //{ // var source = "namespace Foo -> type Bar\n\tfunc Baz -> a = b"; // var expected = "namespace Foo -> type Bar\n\t<Indent>func Baz -> a = b<Dedent><ExpressionBodyEnd><ExpressionBodyEnd>"; // AssertSourceEqualsTokenized(expected, source); //} private void AssertSourceEqualsTokenized(String tokenized, String source) { var inputStream = new AntlrInputStream(source); var lexer = new CovaLexer(inputStream); string joinedTokens = String.Join(String.Empty, lexer.GetAllTokens().Select(x => x.Text)); Assert.Equal(tokenized, joinedTokens); }
public void NewlinesFile(String source, String expected) { var inputStream = new AntlrInputStream(source); var lexer = new CovaLexer(inputStream); string joinedTokens = String.Join(String.Empty, lexer.GetAllTokens().Select(x => x.Text)); Assert.Equal(expected, joinedTokens); }
// static void Main3(String[] args) // { // var filename = "Test.cova"; // var filePath = File.Exists(filename) ? filename : "../../../" + filename; // var fileContents = File.ReadAllText(filePath); // // var parser = new CovaParserExtended(fileContents, filename); // parser.Interpreter.PredictionMode = PredictionMode.SLL; // var file = parser.file(); // // var rootSymbol = InterfaceImplementor.CreateAndInitialize<IModule>(); // rootSymbol.Name = "Module"; // rootSymbol.DefinitionSource = file.ToTextSourceSpan(); // // var symReg = new SymbolRegistrationVisitor(rootSymbol); // symReg.Visit(file); // } static void Main2(String[] args) { //var result = // CommandLine // .Parser // .Default // .ParseArguments(args, typeof(Commands).GetNestedTypes()) // .MapResult( // (Commands.Serve serve) => serve.Debug, // errors => Console.WriteLine(String.Join(Environment.NewLine, errors)) // ); //return Host.CreateDefaultBuilder().RunConsoleAsync(); var filename = "Test.cova"; var filePath = File.Exists(filename) ? filename : "../../../" + filename; var fileContents = File.ReadAllText(filePath); var inputStream = new CodePointCharStream(fileContents) { name = filePath }; var lexer = new CovaLexer(inputStream); // IToken token; // Int32 indents = -1; // UInt32 line = 1; // //Console.Write($"{line,-3}"); // while ((token = lexer.NextToken()).Type != Lexer.Eof) // { // Console.Write(token.Text); // // var tokenTypeName = lexer.GetTokenTypeName(token.Type); // // if (tokenTypeName == "Newline") // // { // // Console.WriteLine(); // // Console.Write($"{++line,-3}"); // // } // // else if (tokenTypeName == "Indent") // // { // // indents++; // // Console.Write(new String('\t', indents)); // // } // // else if (tokenTypeName == "Dedent") // // { // // indents--; // // Console.Write(new String('\t', indents)); // // } // // else if (tokenTypeName == "Dent" | tokenTypeName == "Tab") // // {} // // else // // Console.Write(tokenTypeName + " "); // } // lexer.Reset(); // fileStream.Position = 0; // return; var commonTokenStream = new CommonTokenStream(lexer); var parser = new CovaParser(commonTokenStream); // { BuildParseTree = false }; parser.Interpreter.PredictionMode = PredictionMode.SLL; //var package = new Package { Name = "Cova" }; //using var llvmInitializer = new LLVMInitializer(); //using var module = LLVMModuleRef.CreateWithName("NativeBinary"); //var builder = module.Context.CreateBuilder(); ////using var connection = new SqliteConnection("Data Source=:memory:"); //using var connection = new SqliteConnection("Data Source=Sharable;Mode=Memory;Cache=Shared"); //connection.Open(); //using var context = new Context(connection); //context.Database.EnsureDeleted(); //context.Database.EnsureCreated(); //context.Database.ExecuteSqlRaw("pragma auto_vacuum = full;"); //var funcs = context.Functions.ToList(); //var rootScope = new RootScope(); //var fileScope = new FileScope(filename, rootScope); var rootSymbol = InterfaceImplementor.CreateAndInitialize <IModule>(); rootSymbol.Name = "Module"; //var symReg = new SymbolRegistrationVisitor(rootSymbol); //symReg.Visit(parser.compilationUnit()); //var symbolReg = new SymbolRegistrationListener(rootSymbol); //ParseTreeWalker.Default.Walk(symbolReg, parser.file()); var symbolRes = new SymbolResolutionListener(rootSymbol); }