Permalink
Browse files

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

  • Loading branch information...
siegfriedpammer committed Nov 29, 2010
1 parent 9fef549 commit 28b37d274d1f362d8ee438f613fa27a522825b90
@@ -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>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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.