【发布时间】:2016-01-19 08:25:56
【问题描述】:
我正在编写一个 SVG 解析器,主要是作为学习如何使用 Parsec 的练习。目前我正在使用以下数据类型来表示我的 SVG 文件:
data SVG = Element String [Attribute] [SVG]
| SelfClosingTag [Attribute]
| Body String
| Comment String
| XMLDecl String
这很好用,但是我不确定我的数据类型的 Element String [Attribute] [SVG] 部分。
由于 SVG 的潜在 tags 数量有限,因此我正在考虑使用类型来表示 SVG 元素而不是使用字符串。像这样的:
data SVG = Element TagName [Attribute] [SVG]
| ...
data TagName = A
| AltGlyph
| AltGlyphDef
...
| View
| Vkern
这是个好主意吗?如果有的话,这样做有什么好处? 有没有更优雅的解决方案?
【问题讨论】: