Formatting

This commit is contained in:
Lukasz Baldyga committed 2020-12-03 14:19:43 +00:00
1 parent f39a3d3ca2
commit 07b7e86a63
1 file changed
+142 -142
@@ -75,8 +75,8 @@ namespace Advanced_Software_Engineering {
return new NoOp(); return new NoOp();
} }
break; break;
}
} }
}
//Parse flow verbs //Parse flow verbs
@@ -92,7 +92,7 @@ namespace Advanced_Software_Engineering {
string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first , string commandAfterIf = fullCommand.Substring(fullCommand.IndexOf(",") + 1); // find the first ,
IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional IValue conditional = ValueFactory.CreateValue(rootValueStorage, commandParameters[0]); //make the conditional
IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command IVerb AfterIf = MakeVerb(drawer, commandAfterIf); //make the following command
tmpVerb = new IfChunk(rootValueStorage, conditional, AfterIf); //Create the chunk tmpVerb = new IfChunk(rootValueStorage, conditional, AfterIf); //Create the chunk
parsed = true; parsed = true;
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
@@ -106,7 +106,7 @@ namespace Advanced_Software_Engineering {
DeclareVariable[] methodParameters = new DeclareVariable[] { }; DeclareVariable[] methodParameters = new DeclareVariable[] { };
//if assignments exist, make them //if assignments exist, make them
if(commandParameters.Length > 1) { if (commandParameters.Length > 1) {
List<DeclareVariable> methodParameterList = new List<DeclareVariable>(); List<DeclareVariable> methodParameterList = new List<DeclareVariable>();
for (int index = 1; index < commandParameters.Length; index++) { for (int index = 1; index < commandParameters.Length; index++) {
methodParameterList.Add(new DeclareVariable(rootValueStorage, commandParameters[index])); methodParameterList.Add(new DeclareVariable(rootValueStorage, commandParameters[index]));
@@ -137,7 +137,7 @@ namespace Advanced_Software_Engineering {
int parameterLength = parameters.Count; int parameterLength = parameters.Count;
//Check if method //Check if method
if(drawer.Methods.ContainsKey(command)) { if (drawer.Methods.ContainsKey(command)) {
MethodChunk methodChunk = drawer.Methods[command]; MethodChunk methodChunk = drawer.Methods[command];
string[] methodVariableNames = methodChunk.GetVariableNames().ToArray(); string[] methodVariableNames = methodChunk.GetVariableNames().ToArray();
@@ -184,161 +184,161 @@ namespace Advanced_Software_Engineering {
//process drawing commands and extras //process drawing commands and extras
else switch (command) { else switch (command) {
//Drawing commands //Drawing commands
case "move": case "move":
case "moveto": case "moveto":
//Check parameters //Check parameters
if (parameterLength == 2) { if (parameterLength == 2) {
tmpVerb = new MoveTo(drawer, new PointValue(parameters[0], parameters[1])); tmpVerb = new MoveTo(drawer, new PointValue(parameters[0], parameters[1]));
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "drawto": case "drawto":
case "line": case "line":
case "lineto": case "lineto":
//Check parameters //Check parameters
if (parameterLength == 2) { if (parameterLength == 2) {
tmpVerb = new DrawTo(drawer, new PointValue(parameters[0], parameters[1])); tmpVerb = new DrawTo(drawer, new PointValue(parameters[0], parameters[1]));
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "regularpolygon": case "regularpolygon":
case "rp": case "rp":
//Check parameters //Check parameters
if (parameterLength == 2) { if (parameterLength == 2) {
tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], new IntValue(0), new BoolValue(true)); tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], new IntValue(0), new BoolValue(true));
} else if (parameterLength == 3) { } else if (parameterLength == 3) {
tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], parameters[2], new BoolValue(true)); tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], parameters[2], new BoolValue(true));
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "square": case "square":
//Check parameters //Check parameters
if (parameterLength == 1) { if (parameterLength == 1) {
tmpVerb = new tmpVerb = new
Square(drawer, parameters[0]); Square(drawer, parameters[0]);
} else if (parameterLength == 2) { } else if (parameterLength == 2) {
tmpVerb = new Square(drawer, parameters[0], parameters[1]); tmpVerb = new Square(drawer, parameters[0], parameters[1]);
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "quadrilateral": case "quadrilateral":
//Check parameters //Check parameters
if (parameterLength == 8) { if (parameterLength == 8) {
tmpVerb = new Quadrilateral(drawer, tmpVerb = new Quadrilateral(drawer,
new PointValue(parameters[0], parameters[1]), new PointValue(parameters[0], parameters[1]),
new PointValue(parameters[2], parameters[3]), new PointValue(parameters[2], parameters[3]),
new PointValue(parameters[4], parameters[5]), new PointValue(parameters[4], parameters[5]),
new PointValue(parameters[6], parameters[7]) new PointValue(parameters[6], parameters[7])
); );
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "rectangle": case "rectangle":
//Check parameters //Check parameters
if (parameterLength == 2) { if (parameterLength == 2) {
tmpVerb = new Rectangle(drawer, parameters[0], parameters[1]); tmpVerb = new Rectangle(drawer, parameters[0], parameters[1]);
} else if (parameterLength == 8) { } else if (parameterLength == 8) {
tmpVerb = new Quadrilateral(drawer, tmpVerb = new Quadrilateral(drawer,
new PointValue(parameters[0], parameters[1]), new PointValue(parameters[0], parameters[1]),
new PointValue(parameters[2], parameters[3]), new PointValue(parameters[2], parameters[3]),
new PointValue(parameters[4], parameters[5]), new PointValue(parameters[4], parameters[5]),
new PointValue(parameters[6], parameters[7]) new PointValue(parameters[6], parameters[7])
); );
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "circle": case "circle":
//Check parameters //Check parameters
if (parameterLength == 1) { if (parameterLength == 1) {
tmpVerb = new Circle(drawer, parameters[0]); tmpVerb = new Circle(drawer, parameters[0]);
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "triangle": case "triangle":
//Check parameters //Check parameters
if (parameterLength == 1) { if (parameterLength == 1) {
tmpVerb = new tmpVerb = new
Triangle(drawer, parameters[0]); Triangle(drawer, parameters[0]);
} else if (parameterLength == 2) { } else if (parameterLength == 2) {
tmpVerb = new tmpVerb = new
Triangle(drawer, parameters[0], parameters[1]); Triangle(drawer, parameters[0], parameters[1]);
} else if (parameterLength == 6) { } else if (parameterLength == 6) {
tmpVerb = new Triangle(drawer, tmpVerb = new Triangle(drawer,
new PointValue(parameters[0], parameters[1]), new PointValue(parameters[0], parameters[1]),
new PointValue(parameters[2], parameters[3]), new PointValue(parameters[2], parameters[3]),
new PointValue(parameters[4], parameters[5]) new PointValue(parameters[4], parameters[5])
); );
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "dot": case "dot":
if (parameterLength == 0) { if (parameterLength == 0) {
tmpVerb = new Dot(drawer); tmpVerb = new Dot(drawer);
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
case "clear": case "clear":
if (parameterLength == 0) { if (parameterLength == 0) {
tmpVerb = new Clear(drawer); tmpVerb = new Clear(drawer);
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
case "reset": case "reset":
case "resetpen": case "resetpen":
if (parameterLength == 0) { if (parameterLength == 0) {
tmpVerb = new ResetPen(drawer); tmpVerb = new ResetPen(drawer);
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
case "fillon": case "fillon":
if (parameterLength == 0) { if (parameterLength == 0) {
tmpVerb = new Fill(drawer, true); tmpVerb = new Fill(drawer, true);
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
case "filloff": case "filloff":
if (parameterLength == 0) { if (parameterLength == 0) {
tmpVerb = new Fill(drawer, false); tmpVerb = new Fill(drawer, false);
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
case "pen": case "pen":
if (parameterLength == 1) { if (parameterLength == 1) {
tmpVerb = new PenColor(drawer, parameters[0]); tmpVerb = new PenColor(drawer, parameters[0]);
} else if (parameterLength == 3) { } else if (parameterLength == 3) {
tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2])); tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2]));
} else if (parameterLength == 4) { } else if (parameterLength == 4) {
tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3])); tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
case "fill": case "fill":
if (parameterLength == 1) { if (parameterLength == 1) {
tmpVerb = new FillColor(drawer, parameters[0]); tmpVerb = new FillColor(drawer, parameters[0]);
} else if (parameterLength == 3) { } else if (parameterLength == 3) {
tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], new IntValue(255))); tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], new IntValue(255)));
} else if (parameterLength == 4) { } else if (parameterLength == 4) {
tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3])); tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
} else throw new Exception(command + " has an incorrect number of parameters"); } else throw new Exception(command + " has an incorrect number of parameters");
break; break;
//exit flow //exit flow
case "end": case "end":
if (parameterLength == 0) { if (parameterLength == 0) {
if (currentChunk == null) throw new Exception("Cannot end at root level"); //Todo, describe better if (currentChunk == null) throw new Exception("Cannot end at root level"); //Todo, describe better
verbChunks.Remove(currentChunk); verbChunks.Remove(currentChunk);
chunkDepth = verbChunks.Count - 1; chunkDepth = verbChunks.Count - 1;
tmpVerb = currentChunk; tmpVerb = currentChunk;
currentChunk = verbChunks[chunkDepth]; currentChunk = verbChunks[chunkDepth];
rootValueStorage.DecreaseStack(); rootValueStorage.DecreaseStack();
} else throw new Exception(command + " doesn't take parameters"); } else throw new Exception(command + " doesn't take parameters");
break; break;
default: default:
throw new Exception("Unknown command or cannot parse"); throw new Exception("Unknown command or cannot parse");
} }
} }
if (chunkDepth == 0) return tmpVerb; if (chunkDepth == 0) return tmpVerb;