简体   繁体   English

将一种 DSL 转换为另一种

[英]Translating one DSL to another

I have a specific application DSL query language which I need to translate to Cypher.我有一个特定的应用程序 DSL 查询语言,我需要将其翻译为 Cypher。
This means I get in runtime a string with my domain query language query (SQL like for the example) and need to create a Cypher query string that I can send to the Neo4j server.这意味着我在运行时使用我的域查询语言查询(例如 SQL)获得一个字符串,并且需要创建一个 Cypher 查询字符串,我可以将其发送到 Neo4j 服务器。 I was wondering what are the best options for implementing such a translation engine.我想知道实现这种翻译引擎的最佳选择是什么。
I've read about Xtext and I'm familiar with Antlr but I'm interested if there are better tools for such a task.我已经阅读了 Xtext 并且我熟悉 Antlr,但是如果有更好的工具来完成这样的任务,我很感兴趣。
The translation isn't just translating between the two languages, it needs to translate between the data models of the two, which means I need a good infrastructure for analyzing the source language statement.翻译不仅仅是在两种语言之间进行翻译,还需要在两种语言的数据模型之间进行翻译,这意味着我需要一个良好的基础架构来分析源语言语句。 In addition, if there is some open-source project which does similar things, it can be a great starting point.此外,如果有一些做类似事情的开源项目,这可能是一个很好的起点。

I am no sure why you mention Xtext and Antlr, they are usually used for creating languages (most importantly the parser part) which you are not doing.我不确定你为什么提到 Xtext 和 Antlr,它们通常用于创建你没有做的语言(最重要的是解析器部分)。

You want to determine what kind of translation you want to perform, ie whether you build an AST from your query DSL or not, and whether you generate a Cypher AST or simply Cypher code.您想确定要执行哪种翻译,即是否从查询 DSL 构建 AST,以及是否生成 Cypher AST 或仅生成 Cypher 代码。

If your query DSL looks a lot like Cypher, you could probably easily do code-to-code translation in the Java flavour of your choice.如果您的查询 DSL 看起来很像 Cypher,您可以轻松地在您选择的 Java 风格中进行代码到代码转换。

Otherwise, you will need to build an AST from your query DSL.否则,您将需要从查询 DSL 构建 AST。 Either you already have a parser (note that if you have a runtime for your query DSL it probably includes a parser) or you will have to create it (in ANTLR or even with the Java flavour of your choice).要么您已经有一个解析器(请注意,如果您有一个用于查询 DSL 的运行时,它可能包含一个解析器),或者您必须创建它(在 ANTLR 中,甚至使用您选择的 Java 风格)。 Creating a parser takes time though.但是创建解析器需要时间。

Secondly, you want to determine what you are going to generate: a Cypher AST, if you have the Cypher grammar as some artefact;其次,您要确定要生成的内容:Cypher AST,如果您有 Cypher 语法作为一些人工制品; or more likely, a Cypher query.或者更有可能是 Cypher 查询。 If you have a Cypher AST you can do the transformation with any language, but if you need to generate a Cypher query you will have to write a code generator either in the Java flavour of your choice or using something like Eclipse Acceleo or Eclipse Xtend. If you have a Cypher AST you can do the transformation with any language, but if you need to generate a Cypher query you will have to write a code generator either in the Java flavour of your choice or using something like Eclipse Acceleo or Eclipse Xtend.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM