Commit Graph

13 Commits

Author SHA1 Message Date
Jens Johansen e30f60791a [parser] Don't use the next token as the end on handleSend
Change-Id: Ic4bacffab3fdd9d23bea9b1ecd0f2cfdecb82e2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399060
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-12-05 15:10:34 +00:00
Jens Johansen 5359af23a3 [parser] Add endToken on endSwitchExpressionCase, beginToken on endSwitchExpressionCase
Change-Id: I53c6bae47feb2d4570471a3b91c8e371838fcff5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373245
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-27 05:47:18 +00:00
Jens Johansen fc67d31862 [parser] Listener calls should not be on the next (unrelated) token
When the parser sends events to the listener some events has a pair of
parameters, `beginToken` and `endToken`. Most of these are constructed
in such a way that the `beginToken` is the first token and the
`endToken` is the last token in that construct. This is for instance the
case with `endClassDeclaration`.
It was, however, not the case for `endMetadata` where `endToken` instead
was the next token *not* in the metadata.

In this CL I've found a changed the following to point to the last token
in the construct instead of the next token not in the construct and
renamed the parameter where it made sense:

* `endAssert` --- and renamed `semicolonToken` (which only pointed to
  a semicolon for statements) to `endToken`.
* `endAwaitExpression`
* `endConstLiteral` --- and renamed `token` to `endToken`
* `endConstructorReference`
* `endFieldInitializer` --- and renamed `token` to `endToken`
* `endForIn`
* `endForInBody` --- and renamed `token` to `endToken`
* `endForStatement`
* `endForStatementBody` --- and renamed `token` to `endToken`
* `endFunctionExpression` --- and renamed `token` to `endToken`
* `endInitializer` --- and renamed `token` to `endToken`
* `endInitializers`
* `endInvalidAwaitExpression`
* `endMetadata`
* `endSwitchCase`
* `endTopLevelDeclaration` --- and renamed `nextToken` to `endToken`
* `endWhileStatement`
* `endWhileStatementBody` --- and renamed `token` to `endToken`
* `handleNoConstructorReferenceContinuationAfterTypeArguments`

In the few places in listeners where these values were used I've mostly
updated to do e.g. `endToken.text!` to retain the current behavior.

Change-Id: I25495e160d1eec5c75bcf1313b512cd04bcb1533
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364322
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-04-26 06:59:23 +00:00
Johnni Winther b745fa8923 [cfe] Avoid "Instance of " in parser intertwined test expectations
Change-Id: I7d7b1c9a001c43ec160d26c478bd71b41505f273
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323361
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-09-04 13:06:29 +00:00
Johnni Winther e3621561aa [parser] Refactor BlockKind
Refactors BlockKind to pass an explicit template/message instead
of injecting words directly into the message which leads to
grammatically incorrect english in the output message.

Change-Id: I3b91abf2e5a748f3dfca2cc0a6c877e77b3ad7d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322121
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-09-04 09:40:21 +00:00
Chloe Stefantsova 6b0acfecc1 [cfe] Put patterns in the scopes of their declared variables
Closes https://github.com/dart-lang/sdk/issues/51971

Change-Id: I8ba634e7303bafdb1895c50970fbc80321f4bf6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296581
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-04-24 07:30:00 +00:00
Paul Berry 104ac30cf4 Parser: clean up handling of variable patterns.
The listener API for variable patterns is split into three separate
functions, to handle the three separate behaviors:

- `handleAssignedVariablePattern` for variable names appearing in an
  assignment context (these assign to an existing variable upon a
  successful match).

- `handleDeclaredVariablePattern` for variable declarations appearing
  in a declaration or matching context (these cause a new variable
  name to come into scope).

- `handleWildcardPattern` for wildcards in any context (these don't
  capture the matched value).

Also, responsibility is shifted to the parser for reporting the
following error conditions:

- VariablePatternKeywordInDeclarationContext (e.g.
  `var (var x) = ...;`)

- PatternAssignmentDeclaresVariable (e.g. `[x, var y] = ...;`)

Previously these errors were detected by the implementations, and
weren't fully covering all possible error scenarios.

In the case of VariablePatternKeywordInDeclarationContext, the
listener method `handleDeclaredVariablePattern` is called instead of
`handleAssignedVariablePattern`.  This ensures that no tokens are
dropped from the analyzer AST.  The CFE uses the `inAssignmentPattern`
argument of `handleDeclaredVariablePattern` to distinguish this error
recovery case from a legitimate declared variable pattern.

Fixes #51868.

Bug: https://github.com/dart-lang/sdk/issues/51868
Change-Id: I28ec679b73d64033166721c6460be35f15e23171
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291583
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-03-30 14:12:03 +00:00
Johnni Winther d4a73e3b82 [cfe] Report errors on invalid const patterns with explicit 'const'.
Change-Id: I4f5994fd1f0d5e5289684e0da2f03720706f6d28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-02-15 10:34:28 +00:00
Johnni Winther d89ae3c2c6 [parser] Report error on invalid const patterns
This handles the restriction imposed on the expression occurring
within a constant pattern.

Change-Id: I946d85f908609340a61e060c6bdbee143666fd91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-02-09 12:43:31 +00:00
Chloe Stefantsova e925066175 [cfe] Adjust scoping for variable patterns in switch expressions
Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: I32f3ebf6c45afbbdc291d8f919b14266b646b998
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278347
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-01-05 15:49:44 +00:00
Paul Berry 38cab10852 Patterns parsing: track when variable patterns are in an assignment context.
Variable patterns behave so differently inside a patternAssignment
that we may want to represent them using different AST nodes inside
the analyzer/CFE.  This change adds a boolean flag allowing the
implementation to know what kind of variable pattern it's looking at
when parsing occurs.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I60adf2865bbe24f85b72a79b1360833bf823bd67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273829
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2022-12-07 22:45:40 +00:00
Paul Berry 7b41b6215b Add parser support for patternAssignment.
Bug: https://github.com/dart-lang/sdk/issues/50035, https://github.com/dart-lang/sdk/issues/50502, https://github.com/dart-lang/sdk/issues/50575
Change-Id: Idd3bdcae7cbb95c6f2016bb5d3efc638867f52af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272383
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-11-29 20:16:29 +00:00
Paul Berry fe087f24d1 Add parser support for switch expressions.
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I0c58664d44312f5e9d61d24e34e7cd26dbee3a9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271740
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-11-23 23:04:12 +00:00