|
|
Created:
3 years, 4 months ago by ahe Modified:
3 years, 4 months ago CC:
reviews_dartlang.org, dart-fe-team+reviews_google.com Target Ref:
refs/heads/master Visibility:
Public. |
DescriptionShare code for parsing local functions.
R=danrubel@google.com, johnniwinther@google.com
Committed: https://github.com/dart-lang/sdk/commit/dbe482caac4185532649b0169904e74562c0039e
Patch Set 1 #Patch Set 2 : Update _BodySkippingParser. #
Total comments: 5
Messages
Total messages: 13 (3 generated)
ahe@google.com changed reviewers: + danrubel@google.com, johnniwinther@google.com
Address Dan's comments from CL 2985673002 and more.
lgtm
LGTM
ahe@google.com changed reviewers: + scheglov@google.com
Konstantin, I'd uploaded this CL based on a two week old branch, so when I merged with master, I found a minor issue. I'm going to submit this if all tests pass, but I'd still appreciate if you'd take a look at the changes I've made to _BodySkippingParser.
Description was changed from ========== Share code for parsing local functions. ========== to ========== Share code for parsing local functions. R=danrubel@google.com, johnniwinther@google.com Committed: https://github.com/dart-lang/sdk/commit/dbe482caac4185532649b0169904e74562c0039e ==========
Message was sent while issue was closed.
Committed patchset #2 (id:20001) manually as dbe482caac4185532649b0169904e74562c0039e (presubmit successful).
Message was sent while issue was closed.
https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... File pkg/front_end/lib/src/incremental/unlinked_unit.dart (right): https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... pkg/front_end/lib/src/incremental/unlinked_unit.dart:117: return isExpression ? close.next : close; I don't understand this change. How could it be an expression if it starts with '{'?
Message was sent while issue was closed.
https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... File pkg/front_end/lib/src/incremental/unlinked_unit.dart (right): https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... pkg/front_end/lib/src/incremental/unlinked_unit.dart:117: return isExpression ? close.next : close; On 2017/08/08 01:42:27, scheglov wrote: > I don't understand this change. > How could it be an expression if it starts with '{'? [isExpression] is true if the function is in expression context, for example: print(() { return "I'm a function in expression context."; }()); foo() { print("I'm a function in statement context, or a declaration."); } There's a subtle difference in expression context when using the arrow notation: print(() => "I don't have a trailing semicolon."); bar() => "But I do."; The way I deal with that difference is by having this invariant: when parsing a function expression, this method returns the next token which isn't part of the expression. Otherwise, this is a function declaration, and we always return the end token (which is a "}" for a function with a block body, and semicolon for arrow notation).
Message was sent while issue was closed.
https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... File pkg/front_end/lib/src/incremental/unlinked_unit.dart (right): https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... pkg/front_end/lib/src/incremental/unlinked_unit.dart:117: return isExpression ? close.next : close; On 2017/08/08 08:13:30, ahe wrote: > On 2017/08/08 01:42:27, scheglov wrote: > > I don't understand this change. > > How could it be an expression if it starts with '{'? > > [isExpression] is true if the function is in expression context, for example: > > print(() { return "I'm a function in expression context."; }()); > > foo() { > print("I'm a function in statement context, or a declaration."); > } > > There's a subtle difference in expression context when using the arrow notation: > > print(() => "I don't have a trailing semicolon."); > > bar() => "But I do."; > > The way I deal with that difference is by having this invariant: when parsing a > function expression, this method returns the next token which isn't part of the > expression. Otherwise, this is a function declaration, and we always return the > end token (which is a "}" for a function with a block body, and semicolon for > arrow notation). Now I understand. Thank you.
Message was sent while issue was closed.
https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... File pkg/front_end/lib/src/incremental/unlinked_unit.dart (right): https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... pkg/front_end/lib/src/incremental/unlinked_unit.dart:117: return isExpression ? close.next : close; On 2017/08/08 15:54:57, scheglov wrote: > On 2017/08/08 08:13:30, ahe wrote: > > On 2017/08/08 01:42:27, scheglov wrote: > > > I don't understand this change. > > > How could it be an expression if it starts with '{'? > > > > [isExpression] is true if the function is in expression context, for example: > > > > print(() { return "I'm a function in expression context."; }()); > > > > foo() { > > print("I'm a function in statement context, or a declaration."); > > } > > > > There's a subtle difference in expression context when using the arrow > notation: > > > > print(() => "I don't have a trailing semicolon."); > > > > bar() => "But I do."; > > > > The way I deal with that difference is by having this invariant: when parsing > a > > function expression, this method returns the next token which isn't part of > the > > expression. Otherwise, this is a function declaration, and we always return > the > > end token (which is a "}" for a function with a block body, and semicolon for > > arrow notation). > > Now I understand. > Thank you. Great. Would it have been less confusing initially if I had called this boolean "isFunctionExpression"?
Message was sent while issue was closed.
https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... File pkg/front_end/lib/src/incremental/unlinked_unit.dart (right): https://codereview.chromium.org/2999523002/diff/20001/pkg/front_end/lib/src/i... pkg/front_end/lib/src/incremental/unlinked_unit.dart:117: return isExpression ? close.next : close; On 2017/08/08 16:03:33, ahe wrote: > On 2017/08/08 15:54:57, scheglov wrote: > > On 2017/08/08 08:13:30, ahe wrote: > > > On 2017/08/08 01:42:27, scheglov wrote: > > > > I don't understand this change. > > > > How could it be an expression if it starts with '{'? > > > > > > [isExpression] is true if the function is in expression context, for > example: > > > > > > print(() { return "I'm a function in expression context."; }()); > > > > > > foo() { > > > print("I'm a function in statement context, or a declaration."); > > > } > > > > > > There's a subtle difference in expression context when using the arrow > > notation: > > > > > > print(() => "I don't have a trailing semicolon."); > > > > > > bar() => "But I do."; > > > > > > The way I deal with that difference is by having this invariant: when > parsing > > a > > > function expression, this method returns the next token which isn't part of > > the > > > expression. Otherwise, this is a function declaration, and we always return > > the > > > end token (which is a "}" for a function with a block body, and semicolon > for > > > arrow notation). > > > > Now I understand. > > Thank you. > > Great. Would it have been less confusing initially if I had called this boolean > "isFunctionExpression"? Even better would be "ofFunctionExpression", because the body we're parsing *isn't* function expression, but a part of it. |