atom / language-java

Java package for Atom
Other
62 stars 58 forks source link

Fix catch parameter highlighting #220

Closed Vigilans closed 4 years ago

Vigilans commented 4 years ago

Description of the Change

Uses a two-scope begin/end model to correctly highlight catch parameter.

It wraps Exception ... | or Exception ... ) as a scope, allowing parameter to only sit in this scope, to resolve the parsing sequence issue (first exception type, then parameter identifier).

Alternate Designs

A more complex two-scope design:

Problem: cannot correctly highlight when there's a storage-modifer (like final)

Recursive design:

catch-parameters:
  begin: /(?<=\()|(\|)/
  beginCapture.0.name: 'catch.separator'
  end: /(?=\))/
  patterns:
    - include: storage-modifier
    - include: exception-type
    - include: catch-parameters # recursive
    - include: paramter-identifier

It makes use of the fact that catch (ex1 | ex2 | ex3 param) is in terms of structure the same as catch (ex1 (ex2 (ex3 param) (every time a | is met, the remaining part is actually a new catch-parameter pattern)

Problem: still cannot elegantly handle the base case: catch (final ex3 param).

Benefits

Can correctly highlight catch parameter when it is placed in new line or with a comment in between.

Possible Drawbacks

Don't see any afak.

Applicable Issues

Fix #219

Vigilans commented 4 years ago

I enriched the two testcases by inserting comments into possbile locations related with my changes.

sadikovi commented 4 years ago

Merging to master, thanks!