/// <summary>
/// Main application entrypoint.
/// Might make this have methods and be a class rathern the a program...
/// Then the class can Serialise and Deserialiaze the Regexps
/// </summary>
/// <param name="arg">Command line arguments</param>
static public void Main(String[] arg)
{
// Create a compiler object
RegexCompiler r = new RegexCompiler();
// Print usage if arguments are incorrect
if (arg.Length <= 0 || arg.Length % 2 != 0)
{
Debug.Print("Usage: recompile <patternname> <pattern>");
return;
}
// Loop through arguments, compiling each
for (int i = 0, end = arg.Length; i < end; i += 2)
{
try
{
// Compile regular expression
String name = arg[i];
String pattern = arg[i + 1];
String instructions = name + "Instructions";
// Output program as a nice, formatted char array
Debug.Print("\n // Pre-compiled regular expression '" + pattern + "'\n"
+ " private static char[] " + instructions + " = \n {");
// Compile program for pattern
RegexProgram program = r.Compile(pattern);
// Number of columns in output
int numColumns = 7;
// Loop through program
char[] p = program.Instructions;
for (int j = 0; j < p.Length; j++)
{
// End of column?
if ((j % numColumns) == 0) Debug.Print("\n ");
// Print char as padded hex number
String hex = (0).ToHexString();
while (hex.Length < 4) hex = "0" + hex;
Debug.Print("0x" + hex + ", ");
}
// End of program block
Debug.Print("\n };");
Debug.Print("\n private static REProgram " + name + " = new REProgram(" + instructions + ");");
}
catch (RegexpSyntaxException e)
{
Debug.Print("Syntax error in expression \"" + arg[i] + "\": " + e.ToString());
}
catch (Exception e)
{
Debug.Print("Unexpected exception: " + e.ToString());
}
}
}