$ c。与自动完成$ C编辑器 [英] Code editor with autocomplete

查看:107
本文介绍了$ c。与自动完成$ C编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个code主编对我自己简单的语言:

I need to create a code editor for my own simple language:

className.MethodName(参数名称= 2,...)

className.MethodName(parameterName = 2, ... )

我创建使用ANTLR工具相应的语法和自动生成解析器。现在,我想有类,方法,变量和参数名称自动完成。这份名单应该是上下文相关的,F.E.为类。它应该显示方法和class.Method( - 。参数我要去分析文本,并根据在哪个节点光标显示列表中的问题是,对于不完全code像aaa.bbb (分析器产生一个错误,而不是语法树。
任何想法如何解决这个问题?
也许我是在错误的方式,我不应该解析code,显示自动完成?

I've created the appropriate grammar and autogenerate parser using ANTLR tool. Now I would like to have an autocomplete for class, method, variables and parameter names. This list should be context dependent, f.e. for "class." it should display methods and for "class.Method(" - parameters. I was going to parse the text and display the list depending on in which node the cursor is. The problem is that for incomplete code like "aaa.bbb(" the parser produces an error instead of a syntax tree. Any idea how to solve this problem? Maybe I'm on the wrong way and I shouldn't parse code to display autocomplete?

推荐答案

您需要解析code中的至少某些部分知道要显示的内容。

You need to parse at least some parts of the code to know what to display.

您要么需要一个解析器,允许解析,直到找到一个错误,并继续从那里以后(甚至只是忽略它,并试图修复它自己能够继续解析 - 但它变得非常困难在这里,所以你可以访问的最后一个节点,并使用你的语法和现有的语法树自动完成,或者您缓存最新的语法树,并使用类似的正则表达式看的时候自动完成,并使用高速缓存,看看自动完成的。

You either need a parser that allows parsing until it finds an error and continues from there later (or even just ignore it and tries to fix it itself to be able to continue parsing — but it gets very difficult here, so you can access the last node and use your grammar and the existing syntax tree to autocomplete it, or you cache the latest syntax tree and use something like regex to see when to autocomplete and use the cache to see what to autocomplete.

后来的建议可能是更容易之一,但有一个缺点,高速缓存可能会出最新的在你需要的完成时间(即:你可能会在文件中创建一个新的类,基于全部完工类将无法使用,直到该文件有没有错误)。

The later suggestion might be the easier one but has the disadvantage that the cache might be out-to-date at the time you need the completion (i.e.: you might create a new class in a file, all completions based on that class won’t be available until the file has no errors).

Sidenode:鉴于你分析,你可能会感兴趣的解析防爆pression语法的,他们不正是帮你这个问题,虽然。

Sidenode: Seeing that you do parsing, you might be interested in Parsing Expression Grammars, they don’t exactly help you with that problem, though.

这篇关于$ c。与自动完成$ C编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆