自动完成骨架代码的策略
考虑这个用例场景:我希望自动完成并提供 for 循环和 if else 语句等代码构造的框架。我该如何去做呢?
用户在 VBScript 中编写此行
function add(a,b) 然后按 Enter 键,程序应自动在其后添加行 end function。
另外,我需要处理存在嵌套语句的情况,例如 if 和 endif 语句的情况。
任何帮助将不胜感激。
谢谢
Consider this use case scenario: I wish to auto complete and provide the skeleton for code constructs like for loop and if else statements. How can I go about doing it?
the user writes this line in VBScript,
function add(a,b) and then presses enter, the program should automatically add the line end function after it.
Also I need to handle the case where there are nested statements like in the case of if and endif statements.
Any help would be greatly appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之:按下 Enter 键后读取该行,使用一些正则表达式获取关键字,在字典中查找关键字并执行作为项添加到该键的耦合函数(通过使用函数指针)。
现在,您可以创建一个字典,其中关键字作为键,并使用每个关键字执行的函数名称(作为字符串)。
在单独的模块中,创建与某些关键字耦合的函数集合,例如生成文本
VbNewLine & “结束函数”
。为了保持一切整洁,您应该将正则表达式、关键字和要使用该关键字执行的函数放置在单独的对象(例如字典或自定义创建的类)中。如果您想要实现可扩展性,请不要从 Select Case 开始。
In short: Read the line after the pressing of Enter, grab the keywords with some regular expressions, look up the keywords in a dictionary and perform the coupled function (by use of function pointers) that is added as item to that key.
Now you can create a dictionary with keywords as keys and names of functions (as string) to perform with each keyword.
In a separate module, create a collection of functions that are coupled to certain keywords, like generating the text
VbNewLine & "End Function"
.To keep everything neat, you should place the regular expressions, keywords and functions to perform with that keywords in separate objects like dictionaries or custom created classes. Don't start with Select Case if you want to go for extensibility.