Skip to content

Commit ffe5450

Browse files
committed
init
0 parents  commit ffe5450

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
[Bb]in*/
3+
[Dd]ebug*/
4+
[Oo]bj*/
5+
[Rr]elease*/
6+
7+
*.ReSharper
8+
_ReSharper.*
9+
*.user
10+
*.suo
11+
*.sln.cache
12+
*.resharper

CsParser.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsParser", "CsParser\CsParser.csproj", "{BF6B0D38-AB82-498C-BB79-CB3269008C42}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|x86 = Debug|x86
9+
Release|x86 = Release|x86
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{BF6B0D38-AB82-498C-BB79-CB3269008C42}.Debug|x86.ActiveCfg = Debug|x86
13+
{BF6B0D38-AB82-498C-BB79-CB3269008C42}.Debug|x86.Build.0 = Debug|x86
14+
{BF6B0D38-AB82-498C-BB79-CB3269008C42}.Release|x86.ActiveCfg = Release|x86
15+
{BF6B0D38-AB82-498C-BB79-CB3269008C42}.Release|x86.Build.0 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

CsParser/CsParser.csproj

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{BF6B0D38-AB82-498C-BB79-CB3269008C42}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>CsParser</RootNamespace>
12+
<AssemblyName>CsParser</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<PlatformTarget>x86</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="CSharpParser">
38+
<HintPath>..\contrib\CSharpParser.dll</HintPath>
39+
</Reference>
40+
<Reference Include="Nemerle">
41+
<HintPath>..\contrib\Nemerle.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Nemerle.Peg">
44+
<HintPath>..\contrib\Nemerle.Peg.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.Core" />
48+
<Reference Include="System.Xml.Linq" />
49+
<Reference Include="System.Data.DataSetExtensions" />
50+
<Reference Include="System.Data" />
51+
<Reference Include="System.Xml" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<Compile Include="Program.cs" />
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
</ItemGroup>
57+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
59+
Other similar extension points exist, see Microsoft.Common.targets.
60+
<Target Name="BeforeBuild">
61+
</Target>
62+
<Target Name="AfterBuild">
63+
</Target>
64+
-->
65+
</Project>

CsParser/Program.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using CSharpParser;
7+
using Nemerle.Core;
8+
using Nemerle.Peg;
9+
10+
namespace CsParser
11+
{
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
var fileName = args.Length > 0 ? args[0] : @"../../Program.cs";
17+
18+
var preParser = new PreParser(); // preprocessor parser
19+
20+
SourceSnapshot src; // parsed source
21+
using (var reader = new StreamReader(fileName))
22+
{
23+
src = new SourceSnapshot(reader.ReadToEnd());
24+
}
25+
26+
var preAst = preParser.Parse(src);
27+
28+
var preprocessed = Preprocessor.Run(preAst.Value, new string[0]); // transform AST with preprocessor
29+
30+
var parser = new Parser(); // C# parser
31+
32+
var parsingResult = parser.Parse(preprocessed.Source);
33+
34+
var csAST = parsingResult.Value;
35+
36+
Console.WriteLine("Usings: ");
37+
foreach (var usingDirective in csAST.UsingDirectives)
38+
{
39+
var ns = usingDirective as UsingDirective.Namespace;
40+
if (ns != null)
41+
Console.WriteLine(ns.name);
42+
var alias = usingDirective as UsingDirective.Alias;
43+
if (alias != null)
44+
Console.WriteLine("{0} = {1}", alias.name, alias.alias);
45+
}
46+
47+
Console.WriteLine("\nClasses: ");
48+
ShowMembers(csAST.Members);
49+
}
50+
51+
private static void ShowMembers(IEnumerable<NamespaceNode> namespaceNodes)
52+
{
53+
foreach (var namespaceNode in namespaceNodes)
54+
{
55+
var ns = namespaceNode as NamespaceNode.Namespace;
56+
if (ns != null)
57+
ShowMembers(ns.members);
58+
59+
var typeDecl = namespaceNode as NamespaceNode.TypeDeclaration;
60+
if (typeDecl != null)
61+
Console.WriteLine(typeDecl.decl.Name);
62+
}
63+
64+
}
65+
}
66+
67+
internal class TestClass {}
68+
}

CsParser/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CsParser")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("CsParser")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("cd7aa5b9-72e2-4c48-b5c4-779a0eff5e7e")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

contrib/CSharpParser.dll

1.31 MB
Binary file not shown.

contrib/Nemerle.Peg.dll

12.5 KB
Binary file not shown.

contrib/Nemerle.dll

285 KB
Binary file not shown.

0 commit comments

Comments
 (0)