构建 UI 标记语言解析器的工具
对于一个学校项目,我需要为用户界面(可能基于 XML)标记语言实现一个解析器。根据输入,它会生成一个包含各种 UI 组件(文本区域、输入、面板、对话框等)的 HTML 文档。
您对我可能用于此目的的工具/库有什么建议吗? (在学校我们使用 Flex 和 Bison,但我们被允许使用现代工具——也许是具有 lex 和 yacc 功能的工具)
For a school project, I need to implement a parser for a (probably XML-based) markup language for User Interfaces. Based on the input it generates a HTML document with various UI components (textareas, inputs, panels, dialogs etc.)
Do you have any suggestions for tools/libraries I might use for this?
(At school we use Flex and Bison, but we're allowed to use modern tools -- maybe a tool that has the capabilities of both lex and yacc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的输入(如建议的那样)是 XML,而输出是 HTML,那么这就是 XSLT 的基本用例。 XML 的重点是您不必编写自己的解析器,因此如果这是作为一项工作而不是作为学校项目来完成,那么这将是第一个使用的技术。如果您不能将其表达为转换,那么您可能会寻找其他地方。
如果您不想使用 XML,那么用于纯文本语言的现代工具包括 解析器表达式语法和 DSL 综合工具,例如 微软M。
PEG 使您不必单独进行 lex 和 parse,因此令牌可以是上下文敏感的,而不会使语法复杂化(因为许多令牌在许多语言中),并且某些实现意味着您不必担心左/右递归循环。
DSL 综合工具将基于 IDE 的语法与运行时语义相结合。 Martin Fowler 他的网站上有一本关于 DSL 的书。
但对于作为转换输入的 UI 定义语言,我首先要尝试的是 XML 或其他一些标准结构映射(JSON、YAML),它们可以通过 SAX 接口充当 XSLT 处理器的输入。
If your input is, as suggested, XML and your output is HTML, then that is the basic use case for XSLT. The whole point of XML is that you don't have to write your own parser, so if this was being done as a job of work rather than as a school project that would be the first technique to use. If you can't express it as a transformation, then you might look elsewhere.
If you don't want to use XML, then modern tools for plain-text languages include parser expression grammars and DSL synthesis tools such as Microsoft M.
PEGs free you from having to separately lex and parse, so a token can be context sensitive without complicating the grammar (as many tokens are in many languages), and some implementations mean you don't have to worry about left/right recursive loops.
DSL synthesis tools combine an IDE based grammar with a runtime semantics. Martin Fowler has a book on DSLs on his site.
But for a UI definition language that is the input to a transformation, either XML or some other standard mapping of structure (JSON, YAML) which can act as the input to an XSLT processor via the SAX interface would be the first thing I would try.