static Statements Parse(string code) { RubyParser parser = new RubyParser(); SourceUnitTree unit = parser.CreateAst(@"snippet.rb", new StringTextBuffer(code)); return(unit.Statements); }
public void SetUpFixture() { AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text); using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); UserControl userControl = (UserControl)host.RootComponent; userControl.ClientSize = new Size(489, 389); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(userControl, "userControl1"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null); RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions()); generator.Merge(host, docAdapter, compilationUnit, serializationManager); } } }
public void SetUpFixture() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.rb", GetFormCode()); // Create parse info to return from ParseFile method. parseInfo = new ParseInformation(); // Set the DirtyCompilationUnit to a non-null compilation unit // but with no items in the project content to ensure // that the BestCompilationUnit is used by the generator. parseInfo.SetCompilationUnit(compilationUnit); parseInfo.SetCompilationUnit(new DefaultCompilationUnit(new MockProjectContent()) { ErrorsDuringCompile = true }); // Get the InitializeComponent method from the // compilation unit. expectedInitializeComponentMethod = GetInitializeComponentMethod(compilationUnit); // Find the InitializeComponent method using the designer generator. initializeComponentMethod = RubyDesignerGenerator.GetInitializeComponents(compilationUnit); }
public void SetUpFixture() { MockTextEditorProperties textEditorProperties = new MockTextEditorProperties(); generator = new DerivedRubyDesignerGenerator(); mockViewContent = new MockTextEditorViewContent(); viewContent = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.rb")); viewContent.DesignerCodeFileContent = GetTextEditorCode(); generator.Attach(viewContent); viewContentAttached = generator.GetViewContent(); ParseInformation parseInfo = new ParseInformation(); RubyParser parser = new RubyParser(); ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.rb", GetTextEditorCode()); parseInfo.SetCompilationUnit(parserCompilationUnit); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); Form form = (Form)host.RootComponent; form.ClientSize = new Size(499, 309); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { generator.MergeRootComponentChanges(host, serializationManager); generator.Detach(); } } }
ClassDefinition GetClassDefinition(string code) { RubyParser parser = new RubyParser(); SourceUnitTree unit = parser.CreateAst(@"test.rb", new StringTextBuffer(code)); return(unit.Statements.First as ClassDefinition); }
public void SetUpFixture() { resourceWriter = new MockResourceWriter(); resourceService = new MockResourceService(); resourceService.SetResourceWriter(resourceWriter); AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.Text); using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); Form form = (Form)host.RootComponent; form.ClientSize = new Size(499, 309); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions()); generator.Merge(host, new AvalonEditDocumentAdapter(document, null), compilationUnit, serializationManager); } } }
public void SetLexerTags() { RubyParser parser = new RubyParser(); string[] tags = new string[] { "Test" }; parser.LexerTags = tags; Assert.AreEqual(tags, parser.LexerTags); }
public void SetUpFixture() { string Ruby = "require \"System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\""; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); }
public IExchangableText Convert(UString line) { var buffer = new FormattedTextBuffer(); var visitor = CreateTokenVisitor(buffer); foreach (var token in RubyParser.Parse(line)) { token.Accept(visitor); } return(buffer); }
public void SetUpFixture() { string ruby = "class Class1\r\n" + " @\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); }
public void ParseDoesNotThrowNullReferenceException() { string ruby = "require #"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); ICompilationUnit unit = null; Assert.DoesNotThrow(delegate { unit = parser.Parse(projectContent, @"C:\test.rb", ruby); }); Assert.IsNotNull(unit); }
public void InitializeComponentsUsedInsteadOfInitializeComponent() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); string code = GetFormCode().Replace("InitializeComponent", "InitializeComponents"); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.rb", code); ParseInformation parseInfo = new ParseInformation(compilationUnit); IMethod expectedMethod = GetInitializeComponentMethod(compilationUnit); IMethod method = RubyDesignerGenerator.GetInitializeComponents(compilationUnit); Assert.IsNotNull(method); Assert.AreSame(expectedMethod, method); }
public void SetUpFixture() { string Ruby = "class Test\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\Projects\Test\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; } }
public void SetUpFixture() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\test\MainForm.py", GetRubyCode()); parseInfo = new ParseInformation(compilationUnit); if (compilationUnit.Classes.Count > 0) { mainFormClass = compilationUnit.Classes[0]; initializeComponentsMethod = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(mainFormClass); } }
public void SetUpFixture() { RubyParser parser = new RubyParser(); MockProjectContent mockProjectContent = new MockProjectContent(); ICompilationUnit compilationUnit = parser.Parse(mockProjectContent, @"C:\Projects\Test\MainForm.rb", GetFormCode()); // Create parse info to return from ParseFile method. parseInfo = new ParseInformation(compilationUnit); // Get the InitializeComponent method from the // compilation unit. expectedInitializeComponentMethod = GetInitializeComponentMethod(compilationUnit); // Find the InitializeComponent method using the designer generator. initializeComponentMethod = RubyDesignerGenerator.GetInitializeComponents(compilationUnit); }
public void SetUpFixture() { textEditorOptions = new MockTextEditorOptions(); generator = new DerivedRubyDesignerGenerator(textEditorOptions); mockViewContent = new MockTextEditorViewContent(); viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile(fileName)); generator.Attach(viewContent); viewContent.DesignerCodeFileContent = GetTextEditorCode(); RubyParser parser = new RubyParser(); ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), fileName, GetTextEditorCode()); ParseInformation parseInfo = new ParseInformation(parserCompilationUnit); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; AfterSetUpFixture(); }
public void Compile(string fileName, string source) { Tokens = new List <IToken>(); RubyLexer lexer = null; RubyParser parser = null; var stream = new AntlrInputStream(source); lexer = new RubyLexer(stream); var token = lexer.NextToken(); while (token.Type != RubyLexer.Eof) { Tokens.Add(token); token = lexer.NextToken(); } lexer.Reset(); lexer.Line = 0; lexer._tokenStartCharPositionInLine = 0; var tokenStream = new CommonTokenStream(lexer); parser = new RubyParser(tokenStream); Tree = parser.prog(); var walker = new ParseTreeWalker(); var listener = new RubyCompilerListener(); walker.Walk(listener, Tree); if (listener.HasSemanticError()) { throw new Exception("Semantic error", new Exception(listener.GetErrors())); } else { listener.CreateIRFile(Path.Combine(Environment.CurrentDirectory, $"test_bytecode/{fileName}.pir")); } }
public void SetUpFixture() { AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); MockProjectContent projectContent = new MockProjectContent(); MockProject project = new MockProject(); project.RootNamespace = "RootNamespace"; projectContent.Project = project; ICompilationUnit compilationUnit = parser.Parse(projectContent, @"test.py", document.Text); using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); IEventBindingService eventBindingService = new MockEventBindingService(host); Form form = (Form)host.RootComponent; form.ClientSize = new Size(200, 300); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); // Add picture box PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1"); pictureBox.Location = new Point(0, 0); pictureBox.Image = new Bitmap(10, 10); pictureBox.Size = new Size(100, 120); pictureBox.TabIndex = 0; form.Controls.Add(pictureBox); MockTextEditorOptions options = new MockTextEditorOptions(); options.ConvertTabsToSpaces = true; options.IndentationSize = 4; DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null); RubyDesignerGenerator generator = new RubyDesignerGenerator(options); generator.Merge(host, docAdapter, compilationUnit, serializationManager); } } }
public void SetUpFixture() { string ruby = "def foo\r\n" + "end\r\n" + "\r\n" + "def bar(i)\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { globalClass = compilationUnit.Classes[0]; if (globalClass.Methods.Count > 1) { fooMethod = globalClass.Methods[0]; barMethod = globalClass.Methods[1]; } } // Get folds. TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List <FoldingSection> folds = new List <FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { fooMethodFold = folds[0]; barMethodFold = folds[1]; } }
public void SetUpFixture() { using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(null, new MockOpenedFile("Test.py"))) { viewContent.DesignerCodeFileContent = "class MainForm < Form\r\n" + " def initialize()\r\n" + " self.InitializeComponent()\r\n" + " end\r\n" + "\r\n" + " def InitializeComponent()\r\n" + " end\r\n" + "end"; document = viewContent.DesignerCodeFileDocument; ParseInformation parseInfo = new ParseInformation(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.TextContent); parseInfo.SetCompilationUnit(compilationUnit); using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); Form form = (Form)host.RootComponent; form.ClientSize = new Size(284, 264); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); MockTextEditorProperties textEditorProperties = new MockTextEditorProperties(); textEditorProperties.ConvertTabsToSpaces = true; textEditorProperties.IndentationSize = 1; DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(textEditorProperties); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; generator.Attach(viewContent); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { generator.MergeRootComponentChanges(host, serializationManager); } } } }
public static void Main(string[] args) { if (args.Length > 0) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); RubyLexer lexer = new RubyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); RubyParser parser = new RubyParser(tokens); parser.program(); } else Console.Error.WriteLine("Usage: ruby <input-file>"); }
public void SetUpFixture() { string Ruby = "def foo\r\n" + "end\r\n" + "\r\n" + "def bar(i)\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { globalClass = compilationUnit.Classes[0]; if (globalClass.Methods.Count > 1) { fooMethod = globalClass.Methods[0]; barMethod = globalClass.Methods[1]; } } // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(); ParseInformation parseInfo = new ParseInformation(); parseInfo.SetCompilationUnit(compilationUnit); DocumentFactory docFactory = new DocumentFactory(); IDocument doc = docFactory.CreateDocument(); doc.TextContent = Ruby; List <FoldMarker> markers = foldingStrategy.GenerateFoldMarkers(doc, @"C:\Temp\test.rb", parseInfo); if (markers.Count > 1) { fooMethodMarker = markers[0]; barMethodMarker = markers[1]; } }
public static void Main(string[] args) { if (args.Length > 0) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); RubyLexer lexer = new RubyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); RubyParser parser = new RubyParser(tokens); parser.program(); } else { Console.Error.WriteLine("Usage: ruby <input-file>"); } }
public void SetUpFixture() { string Ruby = "class Test\r\n" + "\tdef foo(sender, e)\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { IClass c = compilationUnit.Classes[0]; method = c.Methods[0]; if (method.Parameters.Count > 1) { senderParameter = method.Parameters[0]; eventArgsParameter = method.Parameters[1]; } } }
public void SetUpFixture() { string ruby = "class Test\r\n" + "\tdef initialize\r\n" + "\t\tputs 'test'\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List <FoldingSection> folds = new List <FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { classFold = folds[0]; methodFold = folds[1]; } } }
public void SetUpFixture() { DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(); MockTextEditorViewContent mockViewContent = new MockTextEditorViewContent(); DerivedFormDesignerViewContent viewContent = new DerivedFormDesignerViewContent(mockViewContent, new MockOpenedFile("Test.rb")); viewContent.DesignerCodeFileContent = GetTextEditorCode(); // Create parse info. RubyParser parser = new RubyParser(); ICompilationUnit unit = parser.Parse(new MockProjectContent(), @"C:\Projects\MyProject\test.rb", GetTextEditorCode()); ParseInformation parseInfo = new ParseInformation(); parseInfo.SetCompilationUnit(unit); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; // Attach view content to generator. generator.Attach(viewContent); // Get compatible methods for event. MockEventDescriptor eventDescriptor = new MockEventDescriptor("Click"); compatibleMethods = generator.GetCompatibleMethods(eventDescriptor); }
public void SetUpFixture() { string Ruby = "class Test\r\n" + "\tdef initialize\r\n" + "\t\tputs 'test'\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(); ParseInformation parseInfo = new ParseInformation(); parseInfo.SetCompilationUnit(compilationUnit); DocumentFactory docFactory = new DocumentFactory(); IDocument doc = docFactory.CreateDocument(); doc.TextContent = Ruby; List <FoldMarker> markers = foldingStrategy.GenerateFoldMarkers(doc, @"C:\Temp\test.py", parseInfo); if (markers.Count > 1) { methodMarker = markers[1]; } } }
public void SetUpFixture() { parser = new RubyParser(); }
public Ruby() { compiler = new RubyCompiler(); parser = new RubyParser(); executableCode = String.Empty; }