using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
namespace Systin.Library{
public sealed class InstructionParser
{
#region Properties and Fields
private string mTestInputText;
/// <summary>
/// Gets the test input.
/// </summary>
/// <value>The test input.</value>
public string TestInput
{
get { return mTestInputText; }
}
private Queue<Instruction> mInstructions;
/// <summary>
/// Gets the instructions.
/// </summary>
/// <value>The instructions.</value>
public Queue<Instruction> Instructions
{
get { return mInstructions; }
}
#endregion
#region Constructors
private InstructionParser() { }
#endregion
#region Private Methods
private static InstructionParser Factory()
{
InstructionParser ip = new InstructionParser();
ip.mInstructions = new Queue<Instruction>();
ip.mTestInputText = "";
return ip;
}
#endregion
#region public static Methods
/// <summary>
/// Parses the specified test method.
/// </summary>
/// <param name="testMethod">The test method.</param>
/// <returns><seealso cref="InstructionParser"/>Instruction Parser object</returns>
public static InstructionParser Parse(string testMethod)
{
#region Validate Input Parms
if (testMethod == null)
{
throw new ArgumentNullException("testMethod");
}
if (testMethod.Length == 0)
{
throw new ArgumentException("testMethod");
}
#endregion
//Get new parser object
InstructionParser instructionParser = InstructionParser.Factory();
instructionParser.mTestInputText = testMethod;
//Regex used to parse lines
string lineRegex = "\\r\\n";
//Split the input up into different lines
String[] lines = Regex.Split(testMethod, lineRegex);
char[] space = {' '};
//Analyze each line
foreach (String line in lines)
{
//Make sure we're only dealing with lines that have data on them
if (line.Length > 0)
{
//Find the Method names on this line.
string[] words = line.Split(space, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words)
{
instructionParser.mInstructions.Enqueue(Instruction.NewInstruction(word));
}
}
}
return instructionParser;
}
#endregion
}
}
|