推断左/右括号?
似乎有人必须努力弄清楚如何推断或建议在哪里放置右括号。我的意思是,突出显示匹配的括号很棒,但建议会更好。这是一个明确的问题吗?如果是这样,它的名字是什么(比如,我应该用谷歌学术搜索什么?)。如果没有,为什么不呢?这是一个明显不可能/提出的问题吗?
也就是说,假设我有一些格式错误的 ruby 代码:
foo.all.map { |i| i.bar }).uniq.compact.reject { |j| j.match /baz/i }
请注意,我缺少最初的括号。我所说的问题是,“当我将光标移到未配对的括号上时,如何建议在开头插入括号?”
如果这不是一个不好提出的问题,为什么还没有人这样做呢?
It seems like someone must have done work on figuring out how to infer or suggest where to put closing parentheses. I mean, highlighting matching parens is great, but suggesting would be even better. Is this a defined problem? If so, what is its name (like, what should I Google Scholar?). If not, why not? Is it an obviously impossible/poorly posed question?
To wit, let's say I have some malformed, ruby code:
foo.all.map { |i| i.bar }).uniq.compact.reject { |j| j.match /baz/i }
Note that I'm missing the initial parenthesis. The problem I'm talking about is, "How do I suggest the insertion of a paren at the beginning when I move my cursor over the unpaired paren?"
If this is not a poorly posed question, why hasn't someone done this yet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
人们可以在用户键入时跟踪“平衡”与“不平衡”括号。一旦括号变得不平衡,就建议一个括号。
例如,输入
(something))
会建议在s
之前添加一个左括号。正确放置“修复”括号可能具有挑战性。例如,如果用户输入something(else))
,则有一个选择:在g
之后或字符串开头插入修复左括号?跟踪平衡括号相对简单:
可能还需要查找不必要的括号,如
a.doSomethingWith((aNumber))
One could keep track of "balanced" vs "unbalanced" parens as the user types. Then suggest a paren as soon as the parens become unbalanced.
For example typing
(something))
would suggest an opening paren befores
. Correctly placing the "fix-it" paren might be challenging. For example if the user typessomething(else))
there's a choice: insert the fix-it opening paren afterg
or at the beginning of the string?Keeping track of balanced parens would be relatively simple:
Might also need to look for unnecessary parens as in
a.doSomethingWith((aNumber))