// Main parse loop void Parse() { // First, try to see if the transform is actually "no transform" if (parseString.Trim() == "none") { return; } // Flag to report an error if a transform function ends too soon bool allowEnd = true; try { while (true) { // First, try to extract a command allowEnd = true; var function = ParseTransformFunctionType(); allowEnd = false; switch (function) { case TransformFunctionType.Matrix: { var a = DelimitedParenthesizedSequence(6, 6); transformFunctions.Add(TransformFunction.Matrix(a[0], a[1], a[2], a[3], a[4], a[5])); break; } case TransformFunctionType.Translate: { var a = DelimitedParenthesizedSequence(1, 2); transformFunctions.Add(TransformFunction.Translate(a[0], a.TryGetOr(1, 0))); break; } case TransformFunctionType.Rotate: { var a = DelimitedParenthesizedSequence(1, 1); transformFunctions.Add(TransformFunction.Rotate(a[0].ToRadians())); break; } case TransformFunctionType.Scale: { var a = DelimitedParenthesizedSequence(1, 2); transformFunctions.Add(TransformFunction.Scale(a[0], a.TryGetOr(1, a[0]))); break; } case TransformFunctionType.SkewX: { var a = DelimitedParenthesizedSequence(1, 1); transformFunctions.Add(TransformFunction.SkewX(a[0].ToRadians())); break; } case TransformFunctionType.SkewY: { var a = DelimitedParenthesizedSequence(1, 1); transformFunctions.Add(TransformFunction.SkewY(a[0].ToRadians())); break; } default: // This code will never come, but the C# compiler cannot detect it throw new ParserException("Unrecognized transform function matched!"); } } } catch (EndParseException) { // The name says it all if (!allowEnd) { throw new ParserException("Unexpected end of transform string!"); } } }