First of all, see if there is a class which is similar to what you want. Use that as a model.
Error handling and reporting on encountering syntactically ill-formed specifications is lamentable.
Keep your specification as simple as possible and use a bracket-balancing editor. If you encounter a syntax error, divide the file in half and try each part. Repeat until you have localized the error. Concentrate initially on the hierarchical structure of diagrams, leaving precise details of alignment. There is implicit typing constraining the hierarchical organization of graphical primitives.