Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Issue 2690073003: When translating analyzer/fasta token streams, match up begin/end tokens. (Closed)

Created:
3 years, 10 months ago by Paul Berry
Modified:
3 years, 10 months ago
CC:
reviews_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

When translating analyzer/fasta token streams, match up begin/end tokens. This required adding some scanner tests in order to validate the translation. Note that the Fasta scanner considers "<", ">", and ">>" to be grouping tokens (with special rules to avoid problems when "<" is used to mean "less than"); analyzer does not. The translation does not handle this correctly yet. R=ahe@google.com Committed: https://github.com/dart-lang/sdk/commit/cf6a01be1976a4707e493df21923ee053b0d1881

Patch Set 1 #

Total comments: 11
Unified diffs Side-by-side diffs Delta from patch set Stats (+184 lines, -1 line) Patch
M pkg/front_end/lib/src/fasta/analyzer/token_utils.dart View 7 chunks +66 lines, -1 line 8 comments Download
M pkg/front_end/test/scanner_fasta_test.dart View 1 chunk +16 lines, -0 lines 2 comments Download
M pkg/front_end/test/scanner_test.dart View 4 chunks +102 lines, -0 lines 1 comment Download

Messages

Total messages: 8 (2 generated)
Paul Berry
3 years, 10 months ago (2017-02-13 22:15:36 UTC) #2
Paul Berry
https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/test/scanner_fasta_test.dart File pkg/front_end/test/scanner_fasta_test.dart (right): https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/test/scanner_fasta_test.dart#newcode96 pkg/front_end/test/scanner_fasta_test.dart:96: // Figure out which recovery technique we want the ...
3 years, 10 months ago (2017-02-13 22:38:59 UTC) #3
ahe
lgtm https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart File pkg/front_end/lib/src/fasta/analyzer/token_utils.dart (right): https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart#newcode83 pkg/front_end/lib/src/fasta/analyzer/token_utils.dart:83: token.endGroup != null && token.endGroup.charOffset != token.charOffset) { ...
3 years, 10 months ago (2017-02-14 11:28:32 UTC) #4
Paul Berry
https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart File pkg/front_end/lib/src/fasta/analyzer/token_utils.dart (right): https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart#newcode83 pkg/front_end/lib/src/fasta/analyzer/token_utils.dart:83: token.endGroup != null && token.endGroup.charOffset != token.charOffset) { On ...
3 years, 10 months ago (2017-02-14 12:40:40 UTC) #5
Paul Berry
Committed patchset #1 (id:1) manually as cf6a01be1976a4707e493df21923ee053b0d1881 (presubmit successful).
3 years, 10 months ago (2017-02-14 12:46:42 UTC) #7
Siggi Cherem (dart-lang)
3 years, 10 months ago (2017-02-15 00:23:10 UTC) #8
Message was sent while issue was closed.
lgtm

https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta...
File pkg/front_end/lib/src/fasta/analyzer/token_utils.dart (right):

https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta...
pkg/front_end/lib/src/fasta/analyzer/token_utils.dart:72: // If this token
closes a group, set the corresponding opener token
super optional nit - (IMO not worth making a change for this).

I'd consider moving some of these algorithm comments out above beginTokenStack
and turn them into some general technique documentation as a whole. In other
words, right now I read this as a description of the implementation, but it's
not as obvious what's the underlying goal.

On a related note, we could also introduce some helper variables which may make
the code more self-explanatory further below. For example:

// Both fasta and analyzer have links from a `BeginToken` to 
// it's matching `EndToken` in a group (like parenthesis and braces).
// However, fasta may contain synthetic tokens from error-recovery 
// that are not mapped to the analyzer token stream. We use these
// stacks to create the appropriate links for non-synthetic tokens in
// the way analyzer expects them to be.

// Note: null is a sentinel value to avoid empty checks below.
var beginTokenStack = <analyzer.BeginToken>[null];
var endTokenStack = <Token>[null];

void matchGroups(Token token, analyzer.Token translatedToken) {
  if (identical(endTokenStack.last, token)) {
    beginTokenStack.last.endToken = translatedToken;
    beginTokenStack.removeLast();
    endTokenStack.removeLast();
  }

  if (translatedToken is analyzer.BeginToken && token is BeginGroupToken) {
    // Synthetic end-tokens use the same offset as the begin token.
    var isSynthetic = token.endGroup?.charOffset = token.charOffset;
    if (!isSynthetic) {
      beginStack.add(translatedToken);
      endStack.add(token.endGroup);
    }
  }

https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/lib/src/fasta...
pkg/front_end/lib/src/fasta/analyzer/token_utils.dart:79: // If this token opens
a group, and there is a matching closer that's not
minor terminology nit here: consider using closing-token, end-token,. or even
closer-token, instead of plain `closer`. For a flip-second I started thinking of
closer in the sense of distance (as opposed to farther), which was a possible
interpretation given that we are also looking into charOffsets

https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/test/scanner_...
File pkg/front_end/test/scanner_test.dart (right):

https://codereview.chromium.org/2690073003/diff/1/pkg/front_end/test/scanner_...
pkg/front_end/test/scanner_test.dart:786: // always matche the preceding
unmatched `{`, even if there are intervening
matche => match

Powered by Google App Engine
This is Rietveld 408576698