Closed Vigilans closed 4 years ago
Can you describe what alternatives were considered?
Hi @sadikovi, I updated how the modification of this PR is formed, and the alternative I tried. Some other alternatives led to similar results.
Workaround is removing whitespace between ] {
.
@sadikovi
Workaround is removing whitespace between ] {.
It reminds me of another alternative I tried...
(?<!\\])\\s*({)
uses negate look back pattern, so although it will not match ]{
, it will match <space>{
in ]<space>{
.
(?<=\\))\\s*({)
, but it will cause the tests to fail since the \s*
prevents inner-class's left bracket {
from being placed in new line.So either array-init or inner-class with suffer from new line or comment in between as long as \s*
is used, this is how another scope is introduced.
Good to know that someone is fixing it now! Is this going to be merged?
@Eskibear hopefully :)
@Vigilans Can you rebase? Also, if I remember correctly it fixes only part of the problem with array initialisers. Could you clarify? Thanks!
Hi, I've rebased my branch and removed a redundant commit.
if I remember correctly it fixes only part of the problem with array initialisers.
This PR fixes full of the problem with the choice of end regex '(?=;|\\)|\\]|\\.|,|\\?|:|}|\\+|\\-|\\*|\\/(?!\\/|\\*)|%|!|&|\\||\\^|=)'
. What falls short are the alternate designs I mentioned, in compare with the repetitively used end regex they fixes only part of the problem.
Thanks! Merging to master.
Great appreciation! So when is it supposed to be shipped?
I will try preparing release this weekend if I have time.
Description of the Change
Similar to #212, it uses a two-scope pattern to distinguish
inner-class
block andarray-initializer
block. it is based on #214 to provide correct end regex forinner-class
andarray-initializer
.Detailed description
Conside how a syntax scope terminates:
Previous new-expr grammar handles following ways of termination:
(?<!\\])\\s*({)
...(})
[
...]
(
...)
[
...]
...{
...}
The usage of
\s*
suffers from new-line and comment-in-between pattern, and this should be relaxed using a two-scope model.Besides,
inner-class
andarray-initializer
do not share same syntax (class-body
andcode
), so they should fall in different scope.So, this PR:
object-new
andarray-declaration
using two different scopes.inner-class
andarray-initializer
in different scopes, with similar names.Alternate Designs
This PR repetitively uses the end regex of new expression:
to determine when a scope terminates. It would be better if we could find a way to reduce its usage.
One possible alternative is: match when inner end token reached (
)
,]
or}
), not the outer token that ends it (the complex end regex).But just like #214, it is hard to tell when
)
or]
is met, whether there will be a{}
block next to it. I (maybe) tried such silly regexes (cannot remember them correctly):(?<=\\)
...}
, inner:{
...(?=}
The problem with it: if there's no}
after)
, it won't ends, causing the wholenew-expr
scope won't ends. e.g.A[] arr = new A[]{ new A(), new A() };
- the comma won't ends firstnew A()
because inner scope eats until}
is met.Benefits
array-initializer
when there's any distance of spaces between ']' and '{'.array-initializer
when '{' is placed at new line or with a comment in between.array-initializer
, in correspondence withinner-class
.Possible Drawbacks
Applicable Issues
Fix #172 Fix #199 Fix https://github.com/redhat-developer/vscode-java/issues/728