initial import of working include -> keyvalues parser (warning: here be dragons)
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40830
This commit is contained in:
parent
608a1f0d80
commit
f94e956f83
1274
tools/incparser/IncParser.cs
Normal file
1274
tools/incparser/IncParser.cs
Normal file
File diff suppressed because it is too large
Load Diff
83
tools/incparser/ParseWriter.cs
Normal file
83
tools/incparser/ParseWriter.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace incparser
|
||||||
|
{
|
||||||
|
class ParseWriter
|
||||||
|
{
|
||||||
|
private int level;
|
||||||
|
private StringBuilder data;
|
||||||
|
|
||||||
|
public int Level
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Contents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return data.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParseWriter()
|
||||||
|
{
|
||||||
|
level = 0;
|
||||||
|
data = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BeginSection(string name)
|
||||||
|
{
|
||||||
|
WriteLine("\"" + PrepString(name) + "\"");
|
||||||
|
WriteLine("{");
|
||||||
|
level++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WritePair(string key, string value)
|
||||||
|
{
|
||||||
|
WriteLine("\"" + PrepString(key) + "\"\t\t\"" + PrepString(value) + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EndSection()
|
||||||
|
{
|
||||||
|
if (--level < 0)
|
||||||
|
{
|
||||||
|
throw new System.Exception("Writer nesting level went out of bounds");
|
||||||
|
}
|
||||||
|
WriteLine("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteLine(string line)
|
||||||
|
{
|
||||||
|
Tabinate();
|
||||||
|
data.Append(line + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Tabinate()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < level; i++)
|
||||||
|
{
|
||||||
|
data.Append("\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string PrepString(string text)
|
||||||
|
{
|
||||||
|
/* Escape all escaped newlines (so they can be unescaped later) */
|
||||||
|
text = text.Replace("\\n", "\\\\n");
|
||||||
|
/* Escape all literal newlines */
|
||||||
|
text = text.Replace("\n", "\\n");
|
||||||
|
text = text.Replace("\r", "");
|
||||||
|
/* Remove escaped quotations */
|
||||||
|
text = text.Replace("\\\"", "\"");
|
||||||
|
/* Replace all quotations with escaped ones now */
|
||||||
|
text = text.Replace("\"", "\\\"");
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
tools/incparser/Program.cs
Normal file
62
tools/incparser/Program.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace incparser
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Environment.Exit(SubMain(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SubMain(string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length < 1)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Usage: incparser <infile>");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
IncParser inc = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inc = new IncParser(args[0]);
|
||||||
|
}
|
||||||
|
catch (ParseException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Initial browsing failed: " + e.Message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to read file: " + e.Message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseWriter pw = new ParseWriter();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inc.Parse(pw);
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pw.Level != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Fatal parse error detected; unable to complete output.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write(pw.Contents);
|
||||||
|
Console.Write("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
tools/incparser/Properties/AssemblyInfo.cs
Normal file
33
tools/incparser/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("incparser")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("AlliedModders")]
|
||||||
|
[assembly: AssemblyProduct("incparser")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © AlliedModders 2007")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("81138f67-d686-415d-b9e2-0fca86c29a22")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
49
tools/incparser/incparser.csproj
Normal file
49
tools/incparser/incparser.csproj
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{064EA9DC-51DC-4EE5-843B-0E3F7069635E}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>incparser</RootNamespace>
|
||||||
|
<AssemblyName>incparser</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="IncParser.cs" />
|
||||||
|
<Compile Include="ParseWriter.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
20
tools/incparser/incparser.sln
Normal file
20
tools/incparser/incparser.sln
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||||
|
# Visual Studio 2005
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "incparser", "incparser.csproj", "{064EA9DC-51DC-4EE5-843B-0E3F7069635E}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{064EA9DC-51DC-4EE5-843B-0E3F7069635E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
Loading…
Reference in New Issue
Block a user