停止问题和后台编译?
我正在尝试弄清楚如何为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于静态文本分析的自动完成听起来比尝试在后台编译更合理。 大多数提供自动完成功能的文本编辑器都使用此方法,尽管它不那么准确。
为此,您可以解析文档以查找名称并记录它们所属的范围。 当该点在文档中移动时,您的自动完成功能会记录该点当前所在的范围,并提供此时应可用的名称。
由于 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.
您
You can