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