停止问题和后台编译?

发布于 2024-07-14 02:57:34 字数 124 浏览 6 评论 0原文

我正在尝试弄清楚如何为 Lua 编写自动完成算法,但由于与许多脚本语言一样,它缺乏静态类型系统,我认为我需要后台编译,但在后台编译期间很容易遇到停止问题,所以我想知道以前是否有人解决过此类问题,以及解决编译和停止问题的标准策略是什么?

I'm trying to figure out how I could write an autocompletion algorithm for Lua, but since as with many scripting languages it lacks a static type system I think I need background compilation, but during background compilation it's easy to hit the halting problem so I was wondering if anyone has solved this sort of thing before, and what are the standard strategies for solving compilation and halting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事还在继续 2024-07-21 02:57:34

基于静态文本分析的自动完成听起来比尝试在后台编译更合理。 大多数提供自动完成功能的文本编辑器都使用此方法,尽管它不那么准确。

为此,您可以解析文档以查找名称并记录它们所属的范围。 当该点在文档中移动时,您的自动完成功能会记录该点当前所在的范围,并提供此时应可用的名称。

由于 LUA 默认情况下是全局作用域,因此如果程序员不使用“local”关键字来缩小作用域,您最终可能会得到一个相当污染的命名空间。

Autocompletion based on static text analysis sounds more reasonable than trying to compile in the background. Most text editors that provide autocomplete use this method, although it isn't as accurate.

To do so, you can parse the document looking for names and recording the scope they belong to. As the point moves through the document, your autocomplete notes the scope it is currently in and provides the names that should be available at that point.

As LUA is global scope by default, you may end up with a fairly polluted namespace if your programmers aren't using the "local" keyword to narrow scopes.

翻了热茶 2024-07-21 02:57:34

  • 实际上可以执行代码来查看特定变量代表什么类型的对象,如果需要太长时间
  • 猜测实际变量将具有什么类型(如果 Lua 有类型),则可以在中间中断执行。 这意味着您必须创建一个类型系统,这是一项不平凡的任务(您必须有足够的限制以允许对对象模型进行推理,并且足够宽松以允许足够的 Lua 程序实际上符合您的模型)。 然而,所有闪亮的新 JavaScript 引擎都尝试这样做,AFAIK,所以你可以在那里寻找指针。
  • 只是从语法猜测。 例如,emacs 补全仅查找相同的前缀,在其他 IDE 通常失败的情况下(C++ 模板),它的作用就像魅力一样

You can

  • actually execute the code to see what kind of object is represented by a particular variable, and cut the execution in the middle if it takes too long
  • guess what type would the actual variable have, if Lua had types. This means you'd have to create a type system, which is a nontrivial task (you have to be enough restrictive to allow reasoning about the object model, and enough permissive for enough Lua programs actually conform to your model). However, all the shiny new javascript engines try to do this, AFAIK, so you could look there for pointers.
  • just guess from the syntax. For example, emacs completion, which only looks for the same prefixes, works like charm in cases where other IDEs usually fail (C++ templates)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文