Add initial string parsing system.

This commit is contained in:
Starbeamrainbowlabs 2016-05-07 20:31:15 +01:00
parent 945ec83feb
commit ecbc2f217f
3 changed files with 39 additions and 1 deletions

View file

@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
namespace cscz namespace cscz
{ {
@ -39,6 +41,29 @@ namespace cscz
{ {
} }
public void ParseString(string source)
{
StringReader lines = new StringReader(source);
string nextLine = string.Empty;
do {
nextLine = lines.ReadLine();
if(nextLine == null) break;
// It's a using statement
if(nextLine.StartsWith("u "))
{
string[] parts = Regex.Split(nextLine.Trim(), @"\s+");
UsingStatements.Add(parts[1]);
}
else
{
Signatures.Add(nextLine.Trim());
}
} while(nextLine != null);
}
public override string ToString() public override string ToString()
{ {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
@ -95,7 +120,6 @@ namespace cscz
// Close the class off and end the file // Close the class off and end the file
result.AppendLine("}"); result.AppendLine("}");
result.AppendLine();
return result.ToString(); return result.ToString();
} }

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Text;
using System.Diagnostics;
namespace cscz namespace cscz
{ {
@ -7,9 +9,16 @@ namespace cscz
public static void Main(string[] args) public static void Main(string[] args)
{ {
ClassGenerator cg = new ClassGenerator(); ClassGenerator cg = new ClassGenerator();
/*
cg.Signatures.Add("float radius"); cg.Signatures.Add("float radius");
cg.Signatures.Add("double weight"); cg.Signatures.Add("double weight");
Console.WriteLine(cg); Console.WriteLine(cg);
*/
string source = Console.In.ReadToEnd();
cg.ParseString(source);
Console.WriteLine(cg);
} }
} }
} }

View file

@ -19,6 +19,11 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole> <Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<CustomCommands>
<CustomCommands>
<Command type="Execute" command="cat Carrot.cscz | ./cscz" workingdir="${TargetDir}" externalConsole="True" pauseExternalConsole="True" />
</CustomCommands>
</CustomCommands>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType> <DebugType>full</DebugType>