To answer your question:
You can do this anyway depending on what you are going to do with the parse tree after you create it.
If all you need to do with you, the SVG parser describes the SGV data form, you just float with the string.
On the other hand, if you want to somehow convert the SVG data to something like graphic (that is, you expect your AST to be evaluated), you will find that it is best to represent all the semantic information in a type system. This will simplify the following steps.
The question, in my opinion, is whether the syntax pass is exactly the place where this happens. (Full disclosure, I am only familiar with SVG.) I suspect that instead of just a flat list of tags, you would be better off with Element each with its own set of necessary and optional attributes. if this conversion "happens later in the program", there is no need to create a TagName data TagName . You can catch all type errors at the same time as you combine attributes in Element s.
On the other hand, a good argument could be analyzed directly into the full tree of Elements, in which case I would drop the general [Attribute] and [SVG] fields of the Element constructor and instead make the corresponding fields in the TagName constructor.
Another answer to a question that you did not ask:
Put the source code in your parse tree earlier. From personal experience, I can say that it becomes more difficult for you, the larger your program.
source share