Permalink
Browse files

added VB to Demo (most code copied from old sample)

  • Loading branch information...
1 parent 9fef549 commit 28b37d274d1f362d8ee438f613fa27a522825b90 @siegfriedpammer siegfriedpammer committed Nov 29, 2010
@@ -40,23 +40,48 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="VBEditDialog.cs" />
+ <Compile Include="VBEditDialog.Designer.cs">
+ <DependentUpon>VBEditDialog.cs</DependentUpon>
+ </Compile>
+ <Compile Include="VBDomView.cs" />
+ <Compile Include="VBDomView.Designer.cs">
+ <DependentUpon>VBDomView.cs</DependentUpon>
+ </Compile>
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="VBDemo.cs" />
+ <Compile Include="VBDemo.Designer.cs">
+ <DependentUpon>VBDemo.cs</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\ICSharpCode.NRefactory.VB\ICSharpCode.NRefactory.VB.csproj">
+ <Project>{7B82B671-419F-45F4-B778-D9286F996EFA}</Project>
+ <Name>ICSharpCode.NRefactory.VB</Name>
+ </ProjectReference>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="VBEditDialog.resx">
+ <DependentUpon>VBEditDialog.cs</DependentUpon>
+ </EmbeddedResource>
+ <EmbeddedResource Include="VBDomView.resx">
+ <DependentUpon>VBDomView.cs</DependentUpon>
+ </EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
+ <EmbeddedResource Include="VBDemo.resx">
+ <DependentUpon>VBDemo.cs</DependentUpon>
+ </EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>
@@ -40,6 +40,8 @@ private void InitializeComponent()
this.csharpParseButton = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.miniToolStrip = new System.Windows.Forms.ToolStrip();
+ this.vbDemo1 = new ICSharpCode.NRefactory.Demo.VBDemo();
+ this.tabPage2.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
@@ -50,6 +52,7 @@ private void InitializeComponent()
//
// tabPage2
//
+ this.tabPage2.Controls.Add(this.vbDemo1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
@@ -177,6 +180,14 @@ private void InitializeComponent()
this.miniToolStrip.Size = new System.Drawing.Size(16, 25);
this.miniToolStrip.TabIndex = 3;
//
+ // vbDemo1
+ //
+ this.vbDemo1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.vbDemo1.Location = new System.Drawing.Point(3, 3);
+ this.vbDemo1.Name = "vbDemo1";
+ this.vbDemo1.Size = new System.Drawing.Size(501, 452);
+ this.vbDemo1.TabIndex = 0;
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -185,6 +196,7 @@ private void InitializeComponent()
this.Controls.Add(this.tabControl1);
this.Name = "MainForm";
this.Text = "NRefactory Demo";
+ this.tabPage2.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
@@ -194,6 +206,7 @@ private void InitializeComponent()
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
+ private ICSharpCode.NRefactory.Demo.VBDemo vbDemo1;
private System.Windows.Forms.Button resolveButton;
private System.Windows.Forms.ToolStrip miniToolStrip;
private System.Windows.Forms.TreeView csharpTreeView;
@@ -0,0 +1,163 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+namespace ICSharpCode.NRefactory.Demo
+{
+ partial class VBDemo
+ {
+ /// <summary>
+ /// Designer variable used to keep track of non-visual components.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Disposes resources used by the control.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing) {
+ if (components != null) {
+ components.Dispose();
+ }
+ }
+ base.Dispose(disposing);
+ }
+
+ /// <summary>
+ /// This method is required for Windows Forms designer support.
+ /// Do not change the method contents inside the source code editor. The Forms designer might
+ /// not be able to load this method if it was changed manually.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.codeView = new System.Windows.Forms.TextBox();
+ this.editNodeButton = new System.Windows.Forms.Button();
+ this.clearSpecialsButton = new System.Windows.Forms.Button();
+ this.syntaxTree = new ICSharpCode.NRefactory.Demo.VBDomView();
+ this.generateCodeButton = new System.Windows.Forms.Button();
+ this.parseButton = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
+ this.splitContainer1.Panel1.SuspendLayout();
+ this.splitContainer1.Panel2.SuspendLayout();
+ this.splitContainer1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // splitContainer1
+ //
+ this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.splitContainer1.Location = new System.Drawing.Point(0, 0);
+ this.splitContainer1.Name = "splitContainer1";
+ this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
+ //
+ // splitContainer1.Panel1
+ //
+ this.splitContainer1.Panel1.Controls.Add(this.codeView);
+ //
+ // splitContainer1.Panel2
+ //
+ this.splitContainer1.Panel2.Controls.Add(this.editNodeButton);
+ this.splitContainer1.Panel2.Controls.Add(this.clearSpecialsButton);
+ this.splitContainer1.Panel2.Controls.Add(this.syntaxTree);
+ this.splitContainer1.Panel2.Controls.Add(this.generateCodeButton);
+ this.splitContainer1.Panel2.Controls.Add(this.parseButton);
+ this.splitContainer1.Size = new System.Drawing.Size(462, 391);
+ this.splitContainer1.SplitterDistance = 173;
+ this.splitContainer1.TabIndex = 1;
+ //
+ // codeView
+ //
+ this.codeView.AcceptsReturn = true;
+ this.codeView.AcceptsTab = true;
+ this.codeView.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.codeView.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.codeView.HideSelection = false;
+ this.codeView.Location = new System.Drawing.Point(0, 0);
+ this.codeView.Multiline = true;
+ this.codeView.Name = "codeView";
+ this.codeView.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+ this.codeView.Size = new System.Drawing.Size(462, 173);
+ this.codeView.TabIndex = 0;
+ this.codeView.Text = "Imports System\r\nClass Test\r\n Public Sub Main(ByVal args As String())\r\n " +
+ " Console.WriteLine(\"Hello, World\")\r\n End Sub\r\nEnd Class";
+ this.codeView.WordWrap = false;
+ //
+ // editNodeButton
+ //
+ this.editNodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.editNodeButton.Location = new System.Drawing.Point(331, 2);
+ this.editNodeButton.Name = "editNodeButton";
+ this.editNodeButton.Size = new System.Drawing.Size(100, 23);
+ this.editNodeButton.TabIndex = 4;
+ this.editNodeButton.Text = "Edit node";
+ this.editNodeButton.UseVisualStyleBackColor = true;
+ this.editNodeButton.Click += new System.EventHandler(this.EditNodeButtonClick);
+ //
+ // clearSpecialsButton
+ //
+ this.clearSpecialsButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.clearSpecialsButton.Location = new System.Drawing.Point(225, 2);
+ this.clearSpecialsButton.Name = "clearSpecialsButton";
+ this.clearSpecialsButton.Size = new System.Drawing.Size(100, 23);
+ this.clearSpecialsButton.TabIndex = 3;
+ this.clearSpecialsButton.Text = "Clear 0 specials";
+ this.clearSpecialsButton.UseVisualStyleBackColor = true;
+ this.clearSpecialsButton.Click += new System.EventHandler(this.ClearSpecialsButtonClick);
+ //
+ // syntaxTree
+ //
+ this.syntaxTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.syntaxTree.Location = new System.Drawing.Point(3, 32);
+ this.syntaxTree.Name = "syntaxTree";
+ this.syntaxTree.Size = new System.Drawing.Size(459, 182);
+ this.syntaxTree.TabIndex = 2;
+ this.syntaxTree.Unit = null;
+ //
+ // generateCodeButton
+ //
+ this.generateCodeButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.generateCodeButton.Location = new System.Drawing.Point(119, 2);
+ this.generateCodeButton.Name = "generateCodeButton";
+ this.generateCodeButton.Size = new System.Drawing.Size(100, 23);
+ this.generateCodeButton.TabIndex = 1;
+ this.generateCodeButton.Text = "Generate";
+ this.generateCodeButton.UseVisualStyleBackColor = true;
+ this.generateCodeButton.Click += new System.EventHandler(this.GenerateCodeButtonClick);
+ //
+ // parseButton
+ //
+ this.parseButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.parseButton.Location = new System.Drawing.Point(13, 2);
+ this.parseButton.Name = "parseButton";
+ this.parseButton.Size = new System.Drawing.Size(100, 23);
+ this.parseButton.TabIndex = 0;
+ this.parseButton.Text = "Parse";
+ this.parseButton.UseVisualStyleBackColor = true;
+ this.parseButton.Click += new System.EventHandler(this.ParseButtonClick);
+ //
+ // VBDemo
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.splitContainer1);
+ this.Name = "VBDemo";
+ this.Size = new System.Drawing.Size(462, 391);
+ this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel1.PerformLayout();
+ this.splitContainer1.Panel2.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
+ this.splitContainer1.ResumeLayout(false);
+ this.ResumeLayout(false);
+ }
+ private System.Windows.Forms.Button clearSpecialsButton;
+ private System.Windows.Forms.Button editNodeButton;
+ private ICSharpCode.NRefactory.Demo.VBDomView syntaxTree;
+ private System.Windows.Forms.TextBox codeView;
+ private System.Windows.Forms.Button generateCodeButton;
+ private System.Windows.Forms.Button parseButton;
+ private System.Windows.Forms.SplitContainer splitContainer1;
+ }
+}
@@ -0,0 +1,78 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using ICSharpCode.NRefactory.VB;
+using ICSharpCode.NRefactory.VB.Parser;
+using ICSharpCode.NRefactory.VB.PrettyPrinter;
+
+namespace ICSharpCode.NRefactory.Demo
+{
+ /// <summary>
+ /// Description of VBDemo.
+ /// </summary>
+ public partial class VBDemo : UserControl
+ {
+ public VBDemo()
+ {
+ //
+ // The InitializeComponent() call is required for Windows Forms designer support.
+ //
+ InitializeComponent();
+ ParseButtonClick(null, null);
+ }
+
+ IList<ISpecial> savedSpecials;
+
+ void ParseButtonClick(object sender, EventArgs e)
+ {
+ using (VBParser parser = new VBParser(new VBLexer(new StringReader(codeView.Text)))) {
+ parser.Parse();
+ // this allows retrieving comments, preprocessor directives, etc. (stuff that isn't part of the syntax)
+ SetSpecials(parser.Lexer.SpecialTracker.RetrieveSpecials());
+ // this retrieves the root node of the result DOM
+ if (parser.Errors.Count > 0) {
+ MessageBox.Show(parser.Errors.ErrorOutput);
+ }
+ syntaxTree.Unit = parser.CompilationUnit;
+ }
+ }
+
+ void GenerateCodeButtonClick(object sender, EventArgs e)
+ {
+ if (syntaxTree.Unit != null) {
+ VBNetOutputVisitor visitor = new VBNetOutputVisitor();
+ // re-insert the comments we saved from the parser into the output
+ using (SpecialNodesInserter.Install(savedSpecials, visitor)) {
+ syntaxTree.Unit.AcceptVisitor(visitor, null);
+ }
+ codeView.Text = visitor.Text.Replace("\t", " ");
+ }
+ }
+
+ void ClearSpecialsButtonClick(object sender, EventArgs e)
+ {
+ SetSpecials(new ISpecial[0]);
+ }
+
+ void EditNodeButtonClick(object sender, EventArgs e)
+ {
+ syntaxTree.EditSelectedNode();
+ }
+
+ void SetSpecials(IList<ISpecial> specials)
+ {
+ savedSpecials = specials;
+ if (specials.Count == 1)
+ clearSpecialsButton.Text = "Clear 1 special";
+ else
+ clearSpecialsButton.Text = "Clear " + specials.Count + " specials";
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 28b37d2

Please sign in to comment.