Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newline before type inside parens #358

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
better test and comments
  • Loading branch information
STRd6 committed Feb 11, 2023
commit 1e7e3eb83a6b753154ff1e6004c6375adac09fcd
2 changes: 2 additions & 0 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -5255,6 +5255,8 @@ TypePrimary
_? IdentifierName (Dot IdentifierName)* TypeArguments?
# NOTE: Check FunctionType before parenthesized in order to distinguish between (a: T) => U and
# A parenthesized inline interface (a: T) ---> ({a: T})
# NOTE: Check Type before ( EOS Type ) to find implicit nested interfaces first. EOS would swallow the
# newline so Nested wouldn't match otherwise.
__ OpenParen ( Type / ( EOS Type ) ) __ CloseParen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be rewritten as follows:

Suggested change
__ OpenParen ( Type / ( EOS Type ) ) __ CloseParen
__ OpenParen ( EOS? Type ) __ CloseParen

Or maybe even simpler:

Suggested change
__ OpenParen ( Type / ( EOS Type ) ) __ CloseParen
__ OpenParen __ Type __ CloseParen

I'm a little confused why Type doesn't allow leading __ already. Ah, I see, it's because TypePrimary has lots of _? prefixes but sometimes-not-always a __ prefix. Seems a bit messy, but this should work...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want it to check Type first to handle nested implicit interfaces. __ Type would swallow the EOS and prevent Nested from matching.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Interesting! Resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but maybe worth adding a comment)


ImportType
Expand Down
18 changes: 1 addition & 17 deletions test/types/type-declaration.civet
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ describe "[TS] type declaration", ->
"""

testCase """
or inside parens
with newline after open paren
---
type SourceMapEntries = (
[number, number, number, number, number] |
Expand All @@ -302,19 +302,3 @@ describe "[TS] type declaration", ->
[number]
)[][]
"""

testCase """
or inside parens
---
type SourceMapEntries = (
[number, number, number, number, number] |
[number, number, number, number] |
[number]
)
---
type SourceMapEntries = (
[number, number, number, number, number] |
[number, number, number, number] |
[number]
)
"""