0

MediaWiki 格式复杂,结合了各种范式和语法,据说没有 php 和 MediaWiki 本身就无法转换。

是否可以通过 Clang Rewriter 上的黑客攻击将 MediaWiki 文本重写为 HTML?Clang 会以某种方式被黑客入侵以递归地插入这些模板吗?

编辑:我并不期待完美的结果,只是想知道这是否合理。

4

1 回答 1

0

I doubt Clang would be helpful; it really, really, wants to be compiler for C-like languages. In particular, I understand it has a hand-written parser for C/C++/ObjectiveC, and I doubt that it would make any sense to try to bend that parser. After parsing, you need to represent the program; Clang's AST classes are really, really intended to model its target languages.

I think what you want is a program transformation system. These tools are designed to let you provide grammars for arbitrary languages, and use source-to-source rewrites to make changes.

Our DMS Software Reengineering Toolkit is one of these. It provides very strong parsing support; it can parse a wide variety languages including IBM COBOL, Java, HTML, C++, and Verilog to give an idea of its span. It accepts multiple language definitions at once; this allows you write source-to-source transformations that map one language to another, which seems to be what you want to do. (The source-to-source transformations idea works pretty well, and other PTS are pure source-to-source, but as a practical matter, implementing a translation tool with pure s-to-s is a little awkward; because not everything you need to do is rewrite. DMS combines procedural code to compute inferences and s-to-s to achieve its effects).

Building a real translator for complex circumstances (as you seem to want to do) isn't easy even with PTS. Just a lot more practical than trying to bend the wrong machinery to the job.

As other commenters have observed, you also have the additional task of reverse-engineering the actual mapping from MediaWiki input to HTML.

于 2013-01-17T15:21:30.987 回答