Compare commits
3 commits
67c85f9b40
...
77c20cf8ef
Author | SHA1 | Date | |
---|---|---|---|
77c20cf8ef | |||
e8e36ae822 | |||
a7e708b8a1 |
3 changed files with 60 additions and 56 deletions
|
@ -7,6 +7,12 @@ using System.IO;
|
||||||
|
|
||||||
namespace cscz
|
namespace cscz
|
||||||
{
|
{
|
||||||
|
public enum GenerationMode
|
||||||
|
{
|
||||||
|
PrivateVariablesWithProperties,
|
||||||
|
PublicVariables
|
||||||
|
}
|
||||||
|
|
||||||
public class ClassGenerator
|
public class ClassGenerator
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -26,17 +32,28 @@ namespace cscz
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> UsingStatements = new List<string>()
|
public List<string> UsingStatements = new List<string>()
|
||||||
{
|
{
|
||||||
"s"
|
"System"
|
||||||
};
|
};
|
||||||
public List<string> Signatures = new List<string>();
|
public List<string> Signatures = new List<string>();
|
||||||
|
|
||||||
public string ClassName = "Carrot";
|
public string ClassName = "Carrot";
|
||||||
|
|
||||||
|
public GenerationMode GenerationMode = GenerationMode.PublicVariables;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to make data members private and create public properties for them instead of making the
|
/// Whether to make data members private and create public properties for them instead of making the
|
||||||
/// data members public.
|
/// data members public.
|
||||||
|
/// This is read only. Please refer to GenerationMode in order to change this field.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CreateProperties = true;
|
public bool CreateProperties
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (GenerationMode == GenerationMode.PrivateVariablesWithProperties)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ClassGenerator ()
|
public ClassGenerator ()
|
||||||
{
|
{
|
||||||
|
@ -108,7 +125,7 @@ namespace cscz
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.AppendLine(string.Format("\tpublic {0} {1};"));
|
result.AppendLine(string.Format("\tpublic {0} {1};", datatypeName, publicDataMemberName));
|
||||||
constructorBody.AppendLine(string.Format("\t\t{0} = in{1};", privateDataMemberName, publicDataMemberName));
|
constructorBody.AppendLine(string.Format("\t\t{0} = in{1};", privateDataMemberName, publicDataMemberName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,22 @@ namespace cscz
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static int Main(string[] args)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> parsedArgs = new Dictionary<string, string>();
|
GenerationMode generationMode = GenerationMode.PublicVariables;
|
||||||
ParseOptions(args, new List<string>(), new List<string>(){ "help", "private" });
|
|
||||||
|
|
||||||
if(args.Length >= 1 && args[0] == "--help")
|
List<string> extras = new List<string>();
|
||||||
|
for(int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
|
if(!args[i].StartsWith("-"))
|
||||||
|
{
|
||||||
|
extras.Add(args[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(args[i].Trim('-'))
|
||||||
|
{
|
||||||
|
case "help":
|
||||||
Assembly asm = Assembly.GetExecutingAssembly();
|
Assembly asm = Assembly.GetExecutingAssembly();
|
||||||
/*** Debug - Lists the names of all embedded resources ***
|
/*** Debug - Lists the names of all embedded resources ***
|
||||||
foreach(string str in asm.GetManifestResourceNames())
|
foreach(string str in asm.GetManifestResourceNames())
|
||||||
|
@ -24,57 +33,27 @@ namespace cscz
|
||||||
string helpText = helpTextReader.ReadToEnd();
|
string helpText = helpTextReader.ReadToEnd();
|
||||||
helpTextReader.Dispose();
|
helpTextReader.Dispose();
|
||||||
Console.WriteLine(helpText);
|
Console.WriteLine(helpText);
|
||||||
return;
|
return 0;
|
||||||
|
case "private":
|
||||||
|
generationMode = GenerationMode.PrivateVariablesWithProperties;
|
||||||
|
break;
|
||||||
|
case "public":
|
||||||
|
generationMode = GenerationMode.PublicVariables;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.Error.WriteLine("Error: Unknown argument '{0}'.", args[i]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassGenerator cg = new ClassGenerator();
|
ClassGenerator cg = new ClassGenerator();
|
||||||
|
cg.GenerationMode = generationMode;
|
||||||
|
|
||||||
string source = Console.In.ReadToEnd();
|
string source = Console.In.ReadToEnd();
|
||||||
cg.ParseString(source);
|
cg.ParseString(source);
|
||||||
|
|
||||||
cg.CreateProperties = !parsedArgs.ContainsKey("private");
|
|
||||||
|
|
||||||
Console.WriteLine(cg);
|
Console.WriteLine(cg);
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Parses command line options out into a dictionary.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="args">The arguments to parse.</param>
|
|
||||||
/// <param name="extraArgs">A list in which to dump any extra arguments found that aren't attached to a flag.</param>
|
|
||||||
/// <param name="noValueArgs">A list of flags which do not take a value.</param>
|
|
||||||
/// <returns>The parsed arguments.</returns>
|
|
||||||
static Dictionary<string, string> ParseOptions(string[] args, List<string> extraArgs, List<string> noValueArgs)
|
|
||||||
{
|
|
||||||
Dictionary<string, string> result = new Dictionary<string, string>();
|
|
||||||
for(int i = 0; i < args.Length; i++)
|
|
||||||
{
|
|
||||||
if (args[i].StartsWith("-"))
|
|
||||||
{
|
|
||||||
string optionKey = args[i].Trim(new char[] { '-', ' ' });
|
|
||||||
if (i < args.Length - 1 && !args[i + 1].StartsWith("-"))
|
|
||||||
{
|
|
||||||
if(!noValueArgs.Contains(optionKey))
|
|
||||||
{
|
|
||||||
result[optionKey] = args[i + 1].Trim();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result[optionKey] = "true";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result[optionKey] = "true";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
extraArgs.Add(args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
examples/carrot.cscz
Normal file
8
examples/carrot.cscz
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
u r
|
||||||
|
# Carrot
|
||||||
|
string name
|
||||||
|
string variety
|
||||||
|
|
||||||
|
float length
|
||||||
|
decimal radius
|
||||||
|
|
Loading…
Reference in a new issue