@@ -12155,20 +12155,12 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
12155
12155
return nullptr ;
12156
12156
}
12157
12157
12158
- if (current_token->get_id () == LEFT_SHIFT)
12159
- {
12160
- lexer.split_current_token (LEFT_ANGLE, LEFT_ANGLE);
12161
- current_token = lexer.peek_token ();
12162
- }
12163
-
12164
- lexer.skip_token ();
12165
-
12166
12158
ParseRestrictions null_denotation_restrictions = restrictions;
12167
12159
null_denotation_restrictions.expr_can_be_stmt = false ;
12168
12160
12169
12161
// parse null denotation (unary part of expression)
12170
12162
std::unique_ptr<AST::Expr> expr
12171
- = null_denotation (current_token, {}, null_denotation_restrictions);
12163
+ = null_denotation ({}, null_denotation_restrictions);
12172
12164
12173
12165
return left_denotations (std::move (expr), right_binding_power,
12174
12166
std::move (outer_attrs), restrictions);
@@ -12236,8 +12228,7 @@ Parser<ManagedTokenSource>::parse_expr (AST::AttrVec outer_attrs,
12236
12228
/* Determines action to take when finding token at beginning of expression. */
12237
12229
template <typename ManagedTokenSource>
12238
12230
std::unique_ptr<AST::Expr>
12239
- Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
12240
- AST::AttrVec outer_attrs,
12231
+ Parser<ManagedTokenSource>::null_denotation (AST::AttrVec outer_attrs,
12241
12232
ParseRestrictions restrictions)
12242
12233
{
12243
12234
/* note: tok is previous character in input stream, not current one, as
@@ -12247,6 +12238,8 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
12247
12238
* denotation and then a left denotation), null denotations handle primaries
12248
12239
* and unary operands (but only prefix unary operands) */
12249
12240
12241
+ auto tok = lexer.peek_token ();
12242
+
12250
12243
switch (tok->get_id ())
12251
12244
{
12252
12245
case IDENTIFIER:
@@ -12255,28 +12248,26 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
12255
12248
case DOLLAR_SIGN:
12256
12249
case CRATE:
12257
12250
case SUPER:
12251
+ case SCOPE_RESOLUTION:
12258
12252
{
12259
12253
// DEBUG
12260
12254
rust_debug (" beginning null denotation identifier handling" );
12261
12255
12262
12256
/* best option: parse as path, then extract identifier, macro,
12263
12257
* struct/enum, or just path info from it */
12264
- AST::PathInExpression path = parse_path_in_expression_pratt (tok );
12258
+ AST::PathInExpression path = parse_path_in_expression ( );
12265
12259
12266
12260
return null_denotation_path (std::move (path), std::move (outer_attrs),
12267
12261
restrictions);
12268
12262
}
12269
- case SCOPE_RESOLUTION:
12270
- {
12271
- // TODO: fix: this is for global paths, i.e. std::string::whatever
12272
- Error error (tok->get_locus (),
12273
- " found null denotation scope resolution operator, and "
12274
- " have not written handling for it" );
12275
- add_error (std::move (error));
12276
-
12277
- return nullptr ;
12278
- }
12279
12263
default :
12264
+ if (tok->get_id () == LEFT_SHIFT)
12265
+ {
12266
+ lexer.split_current_token (LEFT_ANGLE, LEFT_ANGLE);
12267
+ tok = lexer.peek_token ();
12268
+ }
12269
+
12270
+ lexer.skip_token ();
12280
12271
return null_denotation_not_path (std::move (tok), std::move (outer_attrs),
12281
12272
restrictions);
12282
12273
}
@@ -14442,119 +14433,6 @@ Parser<ManagedTokenSource>::parse_struct_expr_tuple_partial (
14442
14433
std::move (outer_attrs), path_locus));
14443
14434
}
14444
14435
14445
- /* Parses a path in expression with the first token passed as a parameter (as
14446
- * it is skipped in token stream). Note that this only parses segment-first
14447
- * paths, not global ones. */
14448
- template <typename ManagedTokenSource>
14449
- AST::PathInExpression
14450
- Parser<ManagedTokenSource>::parse_path_in_expression_pratt (const_TokenPtr tok)
14451
- {
14452
- // HACK-y way of making up for pratt-parsing consuming first token
14453
-
14454
- // DEBUG
14455
- rust_debug (" current peek token when starting path pratt parse: '%s'" ,
14456
- lexer.peek_token ()->get_token_description ());
14457
-
14458
- // create segment vector
14459
- std::vector<AST::PathExprSegment> segments;
14460
-
14461
- std::string initial_str;
14462
-
14463
- switch (tok->get_id ())
14464
- {
14465
- case IDENTIFIER:
14466
- initial_str = tok->get_str ();
14467
- break ;
14468
- case SUPER:
14469
- initial_str = Values::Keywords::SUPER;
14470
- break ;
14471
- case SELF:
14472
- initial_str = Values::Keywords::SELF;
14473
- break ;
14474
- case SELF_ALIAS:
14475
- initial_str = Values::Keywords::SELF_ALIAS;
14476
- break ;
14477
- case CRATE:
14478
- initial_str = Values::Keywords::CRATE;
14479
- break ;
14480
- case DOLLAR_SIGN:
14481
- if (lexer.peek_token ()->get_id () == CRATE)
14482
- {
14483
- initial_str = " $crate" ;
14484
- break ;
14485
- }
14486
- gcc_fallthrough ();
14487
- default :
14488
- add_error (Error (tok->get_locus (),
14489
- " unrecognised token %qs in path in expression" ,
14490
- tok->get_token_description ()));
14491
-
14492
- return AST::PathInExpression::create_error ();
14493
- }
14494
-
14495
- // parse required initial segment
14496
- AST::PathExprSegment initial_segment (initial_str, tok->get_locus ());
14497
- // parse generic args (and turbofish), if they exist
14498
- /* use lookahead to determine if they actually exist (don't want to
14499
- * accidently parse over next ident segment) */
14500
- if (lexer.peek_token ()->get_id () == SCOPE_RESOLUTION
14501
- && lexer.peek_token (1 )->get_id () == LEFT_ANGLE)
14502
- {
14503
- // skip scope resolution
14504
- lexer.skip_token ();
14505
-
14506
- AST::GenericArgs generic_args = parse_path_generic_args ();
14507
-
14508
- initial_segment
14509
- = AST::PathExprSegment (AST::PathIdentSegment (initial_str,
14510
- tok->get_locus ()),
14511
- tok->get_locus (), std::move (generic_args));
14512
- }
14513
- if (initial_segment.is_error ())
14514
- {
14515
- // skip after somewhere?
14516
- // don't necessarily throw error but yeah
14517
-
14518
- // DEBUG
14519
- rust_debug (" initial segment is error - returning null" );
14520
-
14521
- return AST::PathInExpression::create_error ();
14522
- }
14523
- segments.push_back (std::move (initial_segment));
14524
-
14525
- // parse optional segments (as long as scope resolution operator exists)
14526
- const_TokenPtr t = lexer.peek_token ();
14527
- while (t->get_id () == SCOPE_RESOLUTION)
14528
- {
14529
- // skip scope resolution operator
14530
- lexer.skip_token ();
14531
-
14532
- // parse the actual segment - it is an error if it doesn't exist now
14533
- AST::PathExprSegment segment = parse_path_expr_segment ();
14534
- if (segment.is_error ())
14535
- {
14536
- // skip after somewhere?
14537
- Error error (t->get_locus (),
14538
- " could not parse path expression segment" );
14539
- add_error (std::move (error));
14540
-
14541
- return AST::PathInExpression::create_error ();
14542
- }
14543
-
14544
- segments.push_back (std::move (segment));
14545
-
14546
- t = lexer.peek_token ();
14547
- }
14548
-
14549
- // DEBUG:
14550
- rust_debug (
14551
- " current token (just about to return path to null denotation): '%s'" ,
14552
- lexer.peek_token ()->get_token_description ());
14553
-
14554
- return AST::PathInExpression (std::move (segments), {}, tok->get_locus (),
14555
- false );
14556
- }
14557
-
14558
14436
// Parses a closure expression with pratt parsing (from null denotation).
14559
14437
template <typename ManagedTokenSource>
14560
14438
std::unique_ptr<AST::ClosureExpr>
0 commit comments