LCOV - code coverage report
Current view: top level - gcc/rust/parse - rust-parse.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.6 % 23 19
Test Date: 2026-04-20 14:57:17 Functions: 75.0 % 24 18
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* This file is part of GCC.
       2              : 
       3              : GCC is free software; you can redistribute it and/or modify
       4              : it under the terms of the GNU General Public License as published by
       5              : the Free Software Foundation; either version 3, or (at your option)
       6              : any later version.
       7              : 
       8              : GCC is distributed in the hope that it will be useful,
       9              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      10              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11              : GNU General Public License for more details.
      12              : 
      13              : You should have received a copy of the GNU General Public License
      14              : along with GCC; see the file COPYING3.  If not see
      15              : <http://www.gnu.org/licenses/>. */
      16              : 
      17              : #ifndef RUST_PARSE_H
      18              : #define RUST_PARSE_H
      19              : 
      20              : #include "rust-ast.h"
      21              : #include "rust-item.h"
      22              : #include "rust-lex.h"
      23              : #include "rust-ast-full.h"
      24              : #include "rust-diagnostics.h"
      25              : #include "rust-parse-error.h"
      26              : #include "rust-parse-utils.h"
      27              : #include "rust-feature.h"
      28              : #include "rust-feature-store.h"
      29              : 
      30              : #include "expected.h"
      31              : 
      32              : namespace Rust {
      33              : 
      34              : // Left binding powers of operations.
      35              : enum binding_powers
      36              : {
      37              :   // Highest priority
      38              :   LBP_HIGHEST = 100,
      39              : 
      40              :   LBP_PATH = 95,
      41              : 
      42              :   LBP_METHOD_CALL = 90,
      43              : 
      44              :   LBP_FIELD_EXPR = 85,
      45              : 
      46              :   LBP_FUNCTION_CALL = 80,
      47              :   LBP_ARRAY_REF = LBP_FUNCTION_CALL,
      48              : 
      49              :   LBP_QUESTION_MARK = 75, // unary postfix - counts as left
      50              : 
      51              :   LBP_UNARY_PLUS = 70,              // Used only when the null denotation is +
      52              :   LBP_UNARY_MINUS = LBP_UNARY_PLUS, // Used only when the null denotation is -
      53              :   LBP_UNARY_ASTERISK = LBP_UNARY_PLUS, // deref operator - unary prefix
      54              :   LBP_UNARY_EXCLAM = LBP_UNARY_PLUS,
      55              :   LBP_UNARY_AMP = LBP_UNARY_PLUS,
      56              :   LBP_UNARY_AMP_MUT = LBP_UNARY_PLUS,
      57              : 
      58              :   LBP_AS = 65,
      59              : 
      60              :   LBP_MUL = 60,
      61              :   LBP_DIV = LBP_MUL,
      62              :   LBP_MOD = LBP_MUL,
      63              : 
      64              :   LBP_PLUS = 55,
      65              :   LBP_MINUS = LBP_PLUS,
      66              : 
      67              :   LBP_L_SHIFT = 50,
      68              :   LBP_R_SHIFT = LBP_L_SHIFT,
      69              : 
      70              :   LBP_AMP = 45,
      71              : 
      72              :   LBP_CARET = 40,
      73              : 
      74              :   LBP_PIPE = 35,
      75              : 
      76              :   LBP_EQUAL = 30,
      77              :   LBP_NOT_EQUAL = LBP_EQUAL,
      78              :   LBP_SMALLER_THAN = LBP_EQUAL,
      79              :   LBP_SMALLER_EQUAL = LBP_EQUAL,
      80              :   LBP_GREATER_THAN = LBP_EQUAL,
      81              :   LBP_GREATER_EQUAL = LBP_EQUAL,
      82              : 
      83              :   LBP_LOGICAL_AND = 25,
      84              : 
      85              :   LBP_LOGICAL_OR = 20,
      86              : 
      87              :   LBP_DOT_DOT = 15,
      88              :   LBP_DOT_DOT_EQ = LBP_DOT_DOT,
      89              : 
      90              :   // TODO: note all these assig operators are RIGHT associative!
      91              :   LBP_ASSIG = 10,
      92              :   LBP_PLUS_ASSIG = LBP_ASSIG,
      93              :   LBP_MINUS_ASSIG = LBP_ASSIG,
      94              :   LBP_MULT_ASSIG = LBP_ASSIG,
      95              :   LBP_DIV_ASSIG = LBP_ASSIG,
      96              :   LBP_MOD_ASSIG = LBP_ASSIG,
      97              :   LBP_AMP_ASSIG = LBP_ASSIG,
      98              :   LBP_PIPE_ASSIG = LBP_ASSIG,
      99              :   LBP_CARET_ASSIG = LBP_ASSIG,
     100              :   LBP_L_SHIFT_ASSIG = LBP_ASSIG,
     101              :   LBP_R_SHIFT_ASSIG = LBP_ASSIG,
     102              : 
     103              :   // return, break, and closures as lowest priority?
     104              :   LBP_RETURN = 5,
     105              :   LBP_BREAK = LBP_RETURN,
     106              :   LBP_CLOSURE = LBP_RETURN, // unary prefix operators
     107              : 
     108              : #if 0
     109              :   // rust precedences
     110              :   // used for closures
     111              :   PREC_CLOSURE = -40,
     112              :   // used for break, continue, return, and yield
     113              :   PREC_JUMP = -30,
     114              :   // used for range (although weird comment in rustc about this)
     115              :   PREC_RANGE = -10,
     116              :   // used for binary operators mentioned below - also cast, colon (type),
     117              :   // assign, assign_op
     118              :   PREC_BINOP = FROM_ASSOC_OP,
     119              :   // used for box, address_of, let, unary (again, weird comment on let)
     120              :   PREC_PREFIX = 50,
     121              :   // used for await, call, method call, field, index, try,
     122              :   // inline asm, macro invocation
     123              :   PREC_POSTFIX = 60,
     124              :   // used for array, repeat, tuple, literal, path, paren, if,
     125              :   // while, for, 'loop', match, block, try block, async, struct
     126              :   PREC_PAREN = 99,
     127              :   PREC_FORCE_PAREN = 100,
     128              : #endif
     129              : 
     130              :   // lowest priority
     131              :   LBP_LOWEST = 0
     132              : };
     133              : 
     134              : /* HACK: used to resolve the expression-or-statement problem at the end of a
     135              :  * block by allowing either to be returned (technically). Tagged union would
     136              :  * probably take up the same amount of space. */
     137              : struct ExprOrStmt
     138              : {
     139              :   std::unique_ptr<AST::Expr> expr;
     140              :   std::unique_ptr<AST::Stmt> stmt;
     141              : 
     142              :   /* I was going to resist the urge to make this a real class and make it POD,
     143              :    * but construction in steps is too difficult. So it'll just also have a
     144              :    * constructor. */
     145              : 
     146              :   // expression constructor
     147        16198 :   ExprOrStmt (std::unique_ptr<AST::Expr> expr) : expr (std::move (expr)) {}
     148              : 
     149              :   // statement constructor
     150        24184 :   ExprOrStmt (std::unique_ptr<AST::Stmt> stmt) : stmt (std::move (stmt)) {}
     151              : 
     152              :   // macro constructor
     153              :   ExprOrStmt (std::unique_ptr<AST::MacroInvocation> macro)
     154              :     : expr (std::move (macro))
     155              :   {}
     156              : 
     157        80764 :   ~ExprOrStmt () = default;
     158              : 
     159              :   /* no copy constructors/assignment as simple object like this shouldn't
     160              :    * require it */
     161              : 
     162              :   // move constructors
     163        40382 :   ExprOrStmt (ExprOrStmt &&other) = default;
     164              :   ExprOrStmt &operator= (ExprOrStmt &&other) = default;
     165              : 
     166              : private:
     167              :   // private constructor only used for creating error state expr or stmt objects
     168              :   ExprOrStmt (AST::Expr *expr, AST::Stmt *stmt) : expr (expr), stmt (stmt) {}
     169              : 
     170              :   // make this work: have a disambiguation specifically for known statements
     171              :   // (i.e. ';' and 'let'). then, have a special "parse expr or stmt" function
     172              :   // that returns this type. inside it, it parses an expression, and then
     173              :   // determines whether to return expr or stmt via whether the next token is a
     174              :   // semicolon. should be able to disambiguate inside that function between
     175              :   // stmts with blocks and without blocks.
     176              : };
     177              : 
     178              : /* Restrictions on parsing used to signal that certain ambiguous grammar
     179              :  * features should be parsed in a certain way. */
     180              : struct ParseRestrictions
     181              : {
     182              :   bool can_be_struct_expr = true;
     183              :   /* Whether the expression was entered from a unary expression - prevents stuff
     184              :    * like struct exprs being parsed from a dereference. */
     185              :   bool entered_from_unary = false;
     186              :   bool expr_can_be_null = false;
     187              :   bool expr_can_be_stmt = false;
     188              :   bool consume_semi = true;
     189              :   /* Macro invocations that are statements can expand without a semicolon after
     190              :    * the final statement, if it's an expression statement. */
     191              :   bool allow_close_after_expr_stmt = false;
     192              : };
     193              : 
     194              : // Parser implementation for gccrs.
     195              : // TODO: if updated to C++20, ManagedTokenSource would be useful as a concept
     196              : template <typename ManagedTokenSource> class Parser
     197              : {
     198              : public:
     199              :   /**
     200              :    * Consume a token
     201              :    */
     202              :   void skip_token ();
     203              : 
     204              :   /**
     205              :    * Consume a token, reporting an error if it isn't the next token
     206              :    *
     207              :    * @param t ID of the token to consume
     208              :    *
     209              :    * @return true if the token was next, false if it wasn't found
     210              :    */
     211              :   bool skip_token (TokenId t);
     212              : 
     213              :   /**
     214              :    * Consume a token, reporting an error if it isn't the next token
     215              :    *
     216              :    * @param token pointer to similar token to consume
     217              :    *
     218              :    * @return true if the token was next, false if it wasn't found
     219              :    */
     220              :   bool skip_token (const_TokenPtr token);
     221              : 
     222              :   /**
     223              :    * Same as `skip_token` but allows for failure without necessarily reporting
     224              :    * an error
     225              :    *
     226              :    * @param t ID of the token to consume
     227              :    *
     228              :    * @return true if the token was next, false if it wasn't found
     229              :    */
     230              :   bool maybe_skip_token (TokenId t);
     231              : 
     232              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     233              :   parse_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     234              :               ParseRestrictions restrictions = ParseRestrictions ());
     235              : 
     236              :   tl::expected<std::unique_ptr<AST::LiteralExpr>, Parse::Error::Node>
     237              :   parse_literal_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
     238              : 
     239              :   tl::expected<std::unique_ptr<AST::BlockExpr>, Parse::Error::Node>
     240              :   parse_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     241        43362 :                     tl::optional<AST::LoopLabel> = tl::nullopt,
     242              :                     location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     243              : 
     244              :   tl::expected<AST::AnonConst, Parse::Error::Node> parse_anon_const ();
     245              : 
     246              :   tl::expected<std::unique_ptr<AST::ConstBlock>, Parse::Error::Node>
     247              :   parse_const_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     248              :                           location_t loc = UNKNOWN_LOCATION);
     249              : 
     250              :   bool is_macro_rules_def (const_TokenPtr t);
     251              :   tl::expected<std::unique_ptr<AST::Item>, Parse::Error::Item>
     252              :   parse_item (bool called_from_statement);
     253              :   std::unique_ptr<AST::Pattern> parse_pattern ();
     254              :   std::unique_ptr<AST::Pattern> parse_pattern_no_alt ();
     255              : 
     256              :   /**
     257              :    * Parse a statement
     258              :    *
     259              :    * Statement : ';'
     260              :    *    | Item
     261              :    *    | LetStatement
     262              :    *    | ExpressionStatement
     263              :    *    | MacroInvocationSemi
     264              :    */
     265              :   std::unique_ptr<AST::Stmt> parse_stmt (ParseRestrictions restrictions
     266              :                                          = ParseRestrictions ());
     267              :   std::unique_ptr<AST::Type> parse_type (bool save_errors = true);
     268              :   std::unique_ptr<AST::ExternalItem> parse_external_item ();
     269              :   std::unique_ptr<AST::AssociatedItem> parse_trait_item ();
     270              :   std::unique_ptr<AST::AssociatedItem> parse_inherent_impl_item ();
     271              :   std::unique_ptr<AST::AssociatedItem> parse_trait_impl_item ();
     272              :   AST::PathInExpression parse_path_in_expression ();
     273              :   std::vector<std::unique_ptr<AST::LifetimeParam>> parse_lifetime_params ();
     274              :   tl::expected<AST::Visibility, Parse::Error::Visibility> parse_visibility ();
     275              :   std::unique_ptr<AST::IdentifierPattern> parse_identifier_pattern ();
     276              :   tl::expected<std::unique_ptr<AST::Token>, Parse::Error::Node>
     277              :   parse_identifier_or_keyword_token ();
     278              :   tl::expected<std::unique_ptr<AST::TokenTree>, Parse::Error::Node>
     279              :   parse_token_tree ();
     280              : 
     281              :   tl::expected<Parse::AttributeBody, Parse::Error::AttributeBody>
     282              :   parse_attribute_body ();
     283              :   AST::AttrVec parse_inner_attributes ();
     284              :   std::unique_ptr<AST::MacroInvocation>
     285              :   parse_macro_invocation (AST::AttrVec outer_attrs);
     286              : 
     287              :   /*
     288              :    * This has to be public for parsing expressions with outer attributes
     289              :    */
     290              :   AST::AttrVec parse_outer_attributes ();
     291              : 
     292              : private:
     293              :   void skip_after_semicolon ();
     294              :   void skip_after_end ();
     295              :   void skip_after_end_block ();
     296              :   void skip_after_next_block ();
     297              :   void skip_after_end_attribute ();
     298              : 
     299              :   const_TokenPtr expect_token (TokenId t);
     300              :   const_TokenPtr expect_token (const_TokenPtr token_expect);
     301              :   void unexpected_token (const_TokenPtr t);
     302              :   bool skip_generics_right_angle ();
     303              : 
     304              :   void parse_statement_seq (bool (Parser::*done) ());
     305              : 
     306              :   // AST-related stuff - maybe move or something?
     307              :   tl::expected<AST::Attribute, Parse::Error::Attribute>
     308              :   parse_inner_attribute ();
     309              :   tl::expected<AST::Attribute, Parse::Error::Attribute>
     310              :   parse_outer_attribute ();
     311              :   tl::expected<std::unique_ptr<AST::AttrInput>, Parse::Error::AttrInput>
     312              :   parse_attr_input ();
     313              :   Parse::AttributeBody parse_doc_comment ();
     314              : 
     315              :   // Path-related
     316              :   tl::expected<AST::SimplePath, Parse::Error::Node> parse_simple_path ();
     317              :   tl::expected<AST::SimplePathSegment, Parse::Error::SimplePathSegment>
     318              :   parse_simple_path_segment (int base_peek = 0);
     319              :   AST::TypePath parse_type_path ();
     320              :   std::unique_ptr<AST::TypePathSegment> parse_type_path_segment ();
     321              :   tl::expected<AST::PathIdentSegment, Parse::Error::PathIdentSegment>
     322              :   parse_path_ident_segment ();
     323              :   tl::optional<AST::GenericArg> parse_generic_arg ();
     324              :   AST::GenericArgs parse_path_generic_args ();
     325              :   AST::GenericArgsBinding parse_generic_args_binding ();
     326              :   AST::TypePathFunction parse_type_path_function (location_t locus);
     327              :   AST::PathExprSegment parse_path_expr_segment ();
     328              :   AST::QualifiedPathInExpression
     329              :   // When given a pratt_parsed_loc, use it as the location of the
     330              :   // first token parsed in the expression (the parsing of that first
     331              :   // token should be skipped).
     332              :   parse_qualified_path_in_expression (location_t pratt_parsed_loc
     333              :                                       = UNKNOWN_LOCATION);
     334              :   AST::QualifiedPathType parse_qualified_path_type (location_t pratt_parsed_loc
     335              :                                                     = UNKNOWN_LOCATION);
     336              :   AST::QualifiedPathInType parse_qualified_path_in_type ();
     337              : 
     338              :   // Token tree or macro related
     339              :   tl::expected<AST::DelimTokenTree, Parse::Error::Node>
     340              :   parse_delim_token_tree ();
     341              :   std::unique_ptr<AST::MacroRulesDefinition>
     342              :   parse_macro_rules_def (AST::AttrVec outer_attrs);
     343              :   std::unique_ptr<AST::MacroRulesDefinition>
     344              :   parse_decl_macro_def (AST::Visibility vis, AST::AttrVec outer_attrs);
     345              :   std::unique_ptr<AST::MacroInvocation>
     346              :   parse_macro_invocation_semi (AST::AttrVec outer_attrs);
     347              :   AST::MacroRule parse_macro_rule ();
     348              :   AST::MacroMatcher parse_macro_matcher ();
     349              :   std::unique_ptr<AST::MacroMatch> parse_macro_match ();
     350              :   std::unique_ptr<AST::MacroMatchFragment> parse_macro_match_fragment ();
     351              :   std::unique_ptr<AST::MacroMatchRepetition> parse_macro_match_repetition ();
     352              : 
     353              :   // Top-level item-related
     354              :   std::unique_ptr<AST::VisItem> parse_vis_item (AST::AttrVec outer_attrs);
     355              : 
     356              :   // VisItem subclass-related
     357              :   std::unique_ptr<AST::Module> parse_module (AST::Visibility vis,
     358              :                                              AST::AttrVec outer_attrs);
     359              :   std::unique_ptr<AST::ExternCrate>
     360              :   parse_extern_crate (AST::Visibility vis, AST::AttrVec outer_attrs);
     361              :   std::unique_ptr<AST::UseDeclaration>
     362              :   parse_use_decl (AST::Visibility vis, AST::AttrVec outer_attrs);
     363              :   std::unique_ptr<AST::UseTree> parse_use_tree ();
     364              :   std::unique_ptr<AST::Function> parse_function (AST::Visibility vis,
     365              :                                                  AST::AttrVec outer_attrs,
     366              :                                                  bool is_external = false);
     367              :   tl::expected<AST::FunctionQualifiers, Parse::Error::Node>
     368              :   parse_function_qualifiers ();
     369              :   tl::expected<std::pair<std::vector<TokenId>, std::string>, Parse::Error::Node>
     370              :   parse_function_qualifiers_raw (location_t locus);
     371              :   bool
     372              :   ensure_function_qualifier_order (location_t locus,
     373              :                                    const std::vector<TokenId> &found_order);
     374              :   tl::expected<AST::FunctionQualifiers, Parse::Error::Node>
     375              :   function_qualifiers_from_keywords (location_t locus,
     376              :                                      std::vector<TokenId> keywords,
     377              :                                      std::string abi);
     378              :   void emit_function_qualifier_order_error_msg (
     379              :     location_t locus, const std::vector<TokenId> &found_order);
     380              : 
     381              :   std::vector<std::unique_ptr<AST::GenericParam>>
     382              :   parse_generic_params_in_angles ();
     383              :   template <typename EndTokenPred>
     384              :   std::vector<std::unique_ptr<AST::GenericParam>>
     385              :   parse_generic_params (EndTokenPred is_end_token);
     386              :   template <typename EndTokenPred>
     387              :   std::unique_ptr<AST::GenericParam>
     388              :   parse_generic_param (EndTokenPred is_end_token);
     389              : 
     390              :   template <typename EndTokenPred>
     391              :   std::vector<std::unique_ptr<AST::LifetimeParam>>
     392              :   parse_lifetime_params (EndTokenPred is_end_token);
     393              :   std::vector<AST::LifetimeParam> parse_lifetime_params_objs ();
     394              :   template <typename EndTokenPred>
     395              :   std::vector<AST::LifetimeParam>
     396              :   parse_lifetime_params_objs (EndTokenPred is_end_token);
     397              :   template <typename ParseFunction, typename EndTokenPred>
     398              :   auto parse_non_ptr_sequence (
     399              :     ParseFunction parsing_function, EndTokenPred is_end_token,
     400              :     std::string error_msg = "failed to parse generic param in generic params")
     401              :     -> std::vector<decltype (parsing_function ())>;
     402              :   tl::expected<AST::LifetimeParam, Parse::Error::LifetimeParam>
     403              :   parse_lifetime_param ();
     404              :   std::vector<std::unique_ptr<AST::TypeParam>> parse_type_params ();
     405              :   template <typename EndTokenPred>
     406              :   std::vector<std::unique_ptr<AST::TypeParam>>
     407              :   parse_type_params (EndTokenPred is_end_token);
     408              :   std::unique_ptr<AST::TypeParam> parse_type_param ();
     409              :   template <typename EndTokenPred>
     410              :   std::vector<std::unique_ptr<AST::Param>>
     411              :   parse_function_params (EndTokenPred is_end_token);
     412              :   std::unique_ptr<AST::Param> parse_function_param ();
     413              :   std::unique_ptr<AST::Type> parse_function_return_type ();
     414              :   AST::WhereClause parse_where_clause ();
     415              :   std::unique_ptr<AST::WhereClauseItem> parse_where_clause_item (
     416              :     const std::vector<AST::LifetimeParam> &global_for_lifetimes);
     417              :   std::unique_ptr<AST::LifetimeWhereClauseItem>
     418              :   parse_lifetime_where_clause_item ();
     419              :   std::unique_ptr<AST::TypeBoundWhereClauseItem>
     420              :   parse_type_bound_where_clause_item (
     421              :     const std::vector<AST::LifetimeParam> &global_for_lifetimes);
     422              :   std::vector<AST::LifetimeParam> parse_for_lifetimes ();
     423              :   template <typename EndTokenPred>
     424              :   std::vector<std::unique_ptr<AST::TypeParamBound>>
     425              :   parse_type_param_bounds (EndTokenPred is_end_token);
     426              :   std::vector<std::unique_ptr<AST::TypeParamBound>> parse_type_param_bounds ();
     427              :   std::unique_ptr<AST::TypeParamBound> parse_type_param_bound ();
     428              :   std::unique_ptr<AST::TraitBound> parse_trait_bound ();
     429              :   std::vector<AST::Lifetime> parse_lifetime_bounds ();
     430              :   template <typename EndTokenPred>
     431              :   std::vector<AST::Lifetime> parse_lifetime_bounds (EndTokenPred is_end_token);
     432              :   tl::expected<AST::Lifetime, Parse::Error::Lifetime>
     433              :   parse_lifetime (bool allow_elided);
     434              :   AST::Lifetime lifetime_from_token (const_TokenPtr tok);
     435              :   std::unique_ptr<AST::ExternalTypeItem>
     436              :   parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
     437              : 
     438              :   std::unique_ptr<AST::TypeAlias> parse_type_alias (AST::Visibility vis,
     439              :                                                     AST::AttrVec outer_attrs);
     440              :   std::unique_ptr<AST::Struct> parse_struct (AST::Visibility vis,
     441              :                                              AST::AttrVec outer_attrs);
     442              :   std::vector<AST::StructField> parse_struct_fields ();
     443              :   template <typename EndTokenPred>
     444              :   std::vector<AST::StructField> parse_struct_fields (EndTokenPred is_end_token);
     445              :   AST::StructField parse_struct_field ();
     446              :   std::vector<AST::TupleField> parse_tuple_fields ();
     447              :   AST::TupleField parse_tuple_field ();
     448              :   std::unique_ptr<AST::Enum> parse_enum (AST::Visibility vis,
     449              :                                          AST::AttrVec outer_attrs);
     450              :   std::vector<std::unique_ptr<AST::EnumItem>> parse_enum_items ();
     451              :   template <typename EndTokenPred>
     452              :   std::vector<std::unique_ptr<AST::EnumItem>>
     453              :   parse_enum_items (EndTokenPred is_end_token);
     454              :   tl::expected<std::unique_ptr<AST::EnumItem>, Parse::Error::EnumVariant>
     455              :   parse_enum_item ();
     456              :   std::unique_ptr<AST::Union> parse_union (AST::Visibility vis,
     457              :                                            AST::AttrVec outer_attrs);
     458              :   std::unique_ptr<AST::ConstantItem>
     459              :   parse_const_item (AST::Visibility vis, AST::AttrVec outer_attrs);
     460              :   std::unique_ptr<AST::StaticItem> parse_static_item (AST::Visibility vis,
     461              :                                                       AST::AttrVec outer_attrs);
     462              :   std::unique_ptr<AST::Trait> parse_trait (AST::Visibility vis,
     463              :                                            AST::AttrVec outer_attrs);
     464              :   std::unique_ptr<AST::TraitItemType>
     465              :   parse_trait_type (AST::AttrVec outer_attrs, AST::Visibility);
     466              :   std::unique_ptr<AST::ConstantItem>
     467              :   parse_trait_const (AST::AttrVec outer_attrs);
     468              : 
     469              :   tl::expected<std::unique_ptr<AST::Param>, Parse::Error::Self>
     470              :   parse_self_param ();
     471              : 
     472              :   std::unique_ptr<AST::Impl> parse_impl (AST::Visibility vis,
     473              :                                          AST::AttrVec outer_attrs);
     474              :   std::unique_ptr<AST::AssociatedItem>
     475              :   parse_inherent_impl_function_or_method (AST::Visibility vis,
     476              :                                           AST::AttrVec outer_attrs);
     477              :   std::unique_ptr<AST::AssociatedItem>
     478              :   parse_trait_impl_function_or_method (AST::Visibility vis,
     479              :                                        AST::AttrVec outer_attrs);
     480              :   std::unique_ptr<AST::ExternBlock>
     481              :   parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs);
     482              :   std::unique_ptr<AST::Function> parse_method ();
     483              :   std::unique_ptr<AST::Function> parse_async_item (AST::Visibility vis,
     484              :                                                    AST::AttrVec outer_attrs);
     485              : 
     486              :   // Expression-related (Pratt parsed)
     487              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     488              :   parse_expr (int right_binding_power,
     489              :               AST::AttrVec outer_attrs = AST::AttrVec (),
     490              :               ParseRestrictions restrictions = ParseRestrictions ());
     491              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     492              :   null_denotation (AST::AttrVec outer_attrs = AST::AttrVec (),
     493              :                    ParseRestrictions restrictions = ParseRestrictions ());
     494              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     495              :   null_denotation_path (AST::PathInExpression path, AST::AttrVec outer_attrs,
     496              :                         ParseRestrictions restrictions = ParseRestrictions ());
     497              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     498              :   null_denotation_not_path (const_TokenPtr t, AST::AttrVec outer_attrs,
     499              :                             ParseRestrictions restrictions
     500              :                             = ParseRestrictions ());
     501              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     502              :   left_denotations (tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     503              :                       null_denotation,
     504              :                     int right_binding_power, AST::AttrVec outer_attrs,
     505              :                     ParseRestrictions restrictions = ParseRestrictions ());
     506              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Expr>
     507              :   left_denotation (const_TokenPtr t, std::unique_ptr<AST::Expr> left,
     508              :                    AST::AttrVec outer_attrs = AST::AttrVec (),
     509              :                    ParseRestrictions restrictions = ParseRestrictions ());
     510              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     511              :                Parse::Error::Expr>
     512              :   parse_arithmetic_or_logical_expr (
     513              :     const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     514              :     AST::AttrVec outer_attrs, AST::ArithmeticOrLogicalExpr::ExprType expr_type,
     515              :     ParseRestrictions restrictions = ParseRestrictions ());
     516              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     517              :                Parse::Error::Expr>
     518              :   parse_binary_plus_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     519              :                           AST::AttrVec outer_attrs,
     520              :                           ParseRestrictions restrictions
     521              :                           = ParseRestrictions ());
     522              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     523              :                Parse::Error::Expr>
     524              :   parse_binary_minus_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     525              :                            AST::AttrVec outer_attrs,
     526              :                            ParseRestrictions restrictions
     527              :                            = ParseRestrictions ());
     528              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     529              :                Parse::Error::Expr>
     530              :   parse_binary_mult_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     531              :                           AST::AttrVec outer_attrs,
     532              :                           ParseRestrictions restrictions
     533              :                           = ParseRestrictions ());
     534              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     535              :                Parse::Error::Expr>
     536              :   parse_binary_div_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     537              :                          AST::AttrVec outer_attrs,
     538              :                          ParseRestrictions restrictions = ParseRestrictions ());
     539              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     540              :                Parse::Error::Expr>
     541              :   parse_binary_mod_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     542              :                          AST::AttrVec outer_attrs,
     543              :                          ParseRestrictions restrictions = ParseRestrictions ());
     544              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     545              :                Parse::Error::Expr>
     546              :   parse_bitwise_and_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     547              :                           AST::AttrVec outer_attrs,
     548              :                           ParseRestrictions restrictions
     549              :                           = ParseRestrictions ());
     550              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     551              :                Parse::Error::Expr>
     552              :   parse_bitwise_or_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     553              :                          AST::AttrVec outer_attrs,
     554              :                          ParseRestrictions restrictions = ParseRestrictions ());
     555              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     556              :                Parse::Error::Expr>
     557              :   parse_bitwise_xor_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     558              :                           AST::AttrVec outer_attrs,
     559              :                           ParseRestrictions restrictions
     560              :                           = ParseRestrictions ());
     561              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     562              :                Parse::Error::Expr>
     563              :   parse_left_shift_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     564              :                          AST::AttrVec outer_attrs,
     565              :                          ParseRestrictions restrictions = ParseRestrictions ());
     566              :   tl::expected<std::unique_ptr<AST::ArithmeticOrLogicalExpr>,
     567              :                Parse::Error::Expr>
     568              :   parse_right_shift_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     569              :                           AST::AttrVec outer_attrs,
     570              :                           ParseRestrictions restrictions
     571              :                           = ParseRestrictions ());
     572              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     573              :   parse_comparison_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     574              :                          AST::AttrVec outer_attrs,
     575              :                          AST::ComparisonExpr::ExprType expr_type,
     576              :                          ParseRestrictions restrictions = ParseRestrictions ());
     577              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     578              :   parse_binary_equal_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     579              :                            AST::AttrVec outer_attrs,
     580              :                            ParseRestrictions restrictions
     581              :                            = ParseRestrictions ());
     582              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     583              :   parse_binary_not_equal_expr (const_TokenPtr tok,
     584              :                                std::unique_ptr<AST::Expr> left,
     585              :                                AST::AttrVec outer_attrs,
     586              :                                ParseRestrictions restrictions
     587              :                                = ParseRestrictions ());
     588              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     589              :   parse_binary_greater_than_expr (const_TokenPtr tok,
     590              :                                   std::unique_ptr<AST::Expr> left,
     591              :                                   AST::AttrVec outer_attrs,
     592              :                                   ParseRestrictions restrictions
     593              :                                   = ParseRestrictions ());
     594              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     595              :   parse_binary_less_than_expr (const_TokenPtr tok,
     596              :                                std::unique_ptr<AST::Expr> left,
     597              :                                AST::AttrVec outer_attrs,
     598              :                                ParseRestrictions restrictions
     599              :                                = ParseRestrictions ());
     600              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     601              :   parse_binary_greater_equal_expr (const_TokenPtr tok,
     602              :                                    std::unique_ptr<AST::Expr> left,
     603              :                                    AST::AttrVec outer_attrs,
     604              :                                    ParseRestrictions restrictions
     605              :                                    = ParseRestrictions ());
     606              :   tl::expected<std::unique_ptr<AST::ComparisonExpr>, Parse::Error::Expr>
     607              :   parse_binary_less_equal_expr (const_TokenPtr tok,
     608              :                                 std::unique_ptr<AST::Expr> left,
     609              :                                 AST::AttrVec outer_attrs,
     610              :                                 ParseRestrictions restrictions
     611              :                                 = ParseRestrictions ());
     612              :   tl::expected<std::unique_ptr<AST::LazyBooleanExpr>, Parse::Error::Expr>
     613              :   parse_lazy_or_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     614              :                       AST::AttrVec outer_attrs,
     615              :                       ParseRestrictions restrictions = ParseRestrictions ());
     616              :   tl::expected<std::unique_ptr<AST::LazyBooleanExpr>, Parse::Error::Expr>
     617              :   parse_lazy_and_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     618              :                        AST::AttrVec outer_attrs,
     619              :                        ParseRestrictions restrictions = ParseRestrictions ());
     620              :   tl::expected<std::unique_ptr<AST::TypeCastExpr>, Parse::Error::Expr>
     621              :   parse_type_cast_expr (const_TokenPtr tok,
     622              :                         std::unique_ptr<AST::Expr> expr_to_cast,
     623              :                         AST::AttrVec outer_attrs,
     624              :                         ParseRestrictions restrictions = ParseRestrictions ());
     625              :   tl::expected<std::unique_ptr<AST::AssignmentExpr>, Parse::Error::Expr>
     626              :   parse_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     627              :                     AST::AttrVec outer_attrs,
     628              :                     ParseRestrictions restrictions = ParseRestrictions ());
     629              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     630              :   parse_compound_assignment_expr (
     631              :     const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     632              :     AST::AttrVec outer_attrs, AST::CompoundAssignmentExpr::ExprType expr_type,
     633              :     ParseRestrictions restrictions = ParseRestrictions ());
     634              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     635              :   parse_plus_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     636              :                          AST::AttrVec outer_attrs,
     637              :                          ParseRestrictions restrictions = ParseRestrictions ());
     638              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     639              :   parse_minus_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     640              :                           AST::AttrVec outer_attrs,
     641              :                           ParseRestrictions restrictions
     642              :                           = ParseRestrictions ());
     643              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     644              :   parse_mult_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     645              :                          AST::AttrVec outer_attrs,
     646              :                          ParseRestrictions restrictions = ParseRestrictions ());
     647              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     648              :   parse_div_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     649              :                         AST::AttrVec outer_attrs,
     650              :                         ParseRestrictions restrictions = ParseRestrictions ());
     651              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     652              :   parse_mod_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     653              :                         AST::AttrVec outer_attrs,
     654              :                         ParseRestrictions restrictions = ParseRestrictions ());
     655              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     656              :   parse_and_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     657              :                         AST::AttrVec outer_attrs,
     658              :                         ParseRestrictions restrictions = ParseRestrictions ());
     659              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     660              :   parse_or_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     661              :                        AST::AttrVec outer_attrs,
     662              :                        ParseRestrictions restrictions = ParseRestrictions ());
     663              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     664              :   parse_xor_assig_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left,
     665              :                         AST::AttrVec outer_attrs,
     666              :                         ParseRestrictions restrictions = ParseRestrictions ());
     667              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     668              :   parse_left_shift_assig_expr (const_TokenPtr tok,
     669              :                                std::unique_ptr<AST::Expr> left,
     670              :                                AST::AttrVec outer_attrs,
     671              :                                ParseRestrictions restrictions
     672              :                                = ParseRestrictions ());
     673              :   tl::expected<std::unique_ptr<AST::CompoundAssignmentExpr>, Parse::Error::Expr>
     674              :   parse_right_shift_assig_expr (const_TokenPtr tok,
     675              :                                 std::unique_ptr<AST::Expr> left,
     676              :                                 AST::AttrVec outer_attrs,
     677              :                                 ParseRestrictions restrictions
     678              :                                 = ParseRestrictions ());
     679              :   tl::expected<std::unique_ptr<AST::AwaitExpr>, Parse::Error::Expr>
     680              :   parse_await_expr (const_TokenPtr tok,
     681              :                     std::unique_ptr<AST::Expr> expr_to_await,
     682              :                     AST::AttrVec outer_attrs);
     683              :   tl::expected<std::unique_ptr<AST::MethodCallExpr>, Parse::Error::Expr>
     684              :   parse_method_call_expr (const_TokenPtr tok,
     685              :                           std::unique_ptr<AST::Expr> receiver_expr,
     686              :                           AST::AttrVec outer_attrs,
     687              :                           ParseRestrictions restrictions
     688              :                           = ParseRestrictions ());
     689              :   tl::expected<std::unique_ptr<AST::CallExpr>, Parse::Error::Expr>
     690              :   parse_function_call_expr (const_TokenPtr tok,
     691              :                             std::unique_ptr<AST::Expr> function_expr,
     692              :                             AST::AttrVec outer_attrs,
     693              :                             ParseRestrictions restrictions
     694              :                             = ParseRestrictions ());
     695              :   tl::expected<std::unique_ptr<AST::RangeExpr>, Parse::Error::Expr>
     696              :   parse_led_range_exclusive_expr (const_TokenPtr tok,
     697              :                                   std::unique_ptr<AST::Expr> left,
     698              :                                   AST::AttrVec outer_attrs,
     699              :                                   ParseRestrictions restrictions
     700              :                                   = ParseRestrictions ());
     701              :   tl::expected<std::unique_ptr<AST::RangeExpr>, Parse::Error::Expr>
     702              :   parse_nud_range_exclusive_expr (const_TokenPtr tok, AST::AttrVec outer_attrs);
     703              :   tl::expected<std::unique_ptr<AST::RangeFromToInclExpr>, Parse::Error::Expr>
     704              :   parse_range_inclusive_expr (const_TokenPtr tok,
     705              :                               std::unique_ptr<AST::Expr> left,
     706              :                               AST::AttrVec outer_attrs,
     707              :                               ParseRestrictions restrictions
     708              :                               = ParseRestrictions ());
     709              :   tl::expected<std::unique_ptr<AST::RangeToInclExpr>, Parse::Error::Expr>
     710              :   parse_range_to_inclusive_expr (const_TokenPtr tok, AST::AttrVec outer_attrs);
     711              :   tl::expected<std::unique_ptr<AST::TupleIndexExpr>, Parse::Error::Expr>
     712              :   parse_tuple_index_expr (const_TokenPtr tok,
     713              :                           std::unique_ptr<AST::Expr> tuple_expr,
     714              :                           AST::AttrVec outer_attrs,
     715              :                           ParseRestrictions restrictions
     716              :                           = ParseRestrictions ());
     717              :   tl::expected<std::unique_ptr<AST::FieldAccessExpr>, Parse::Error::Expr>
     718              :   parse_field_access_expr (const_TokenPtr tok,
     719              :                            std::unique_ptr<AST::Expr> struct_expr,
     720              :                            AST::AttrVec outer_attrs,
     721              :                            ParseRestrictions restrictions
     722              :                            = ParseRestrictions ());
     723              :   tl::expected<std::unique_ptr<AST::ArrayIndexExpr>, Parse::Error::Expr>
     724              :   parse_index_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> array_expr,
     725              :                     AST::AttrVec outer_attrs,
     726              :                     ParseRestrictions restrictions = ParseRestrictions ());
     727              :   std::unique_ptr<AST::MacroInvocation> parse_macro_invocation_partial (
     728              :     AST::PathInExpression path, AST::AttrVec outer_attrs,
     729              :     ParseRestrictions restrictions = ParseRestrictions ());
     730              :   tl::expected<std::unique_ptr<AST::StructExprStruct>, Parse::Error::Expr>
     731              :   parse_struct_expr_struct_partial (AST::PathInExpression path,
     732              :                                     AST::AttrVec outer_attrs);
     733              :   tl::expected<std::unique_ptr<AST::CallExpr>, Parse::Error::Expr>
     734              :   parse_struct_expr_tuple_partial (AST::PathInExpression path,
     735              :                                    AST::AttrVec outer_attrs);
     736              :   tl::expected<std::unique_ptr<AST::ClosureExpr>, Parse::Error::Expr>
     737              :   parse_closure_expr_pratt (const_TokenPtr tok,
     738              :                             AST::AttrVec outer_attrs = AST::AttrVec ());
     739              :   std::unique_ptr<AST::TupleIndexExpr> parse_tuple_index_expr_float (
     740              :     const_TokenPtr tok, std::unique_ptr<AST::Expr> tuple_expr,
     741              :     AST::AttrVec outer_attrs,
     742              :     ParseRestrictions restrictions = ParseRestrictions ());
     743              : 
     744              :   // When given a pratt_parsed_loc, use it as the location of the
     745              :   // first token parsed in the expression (the parsing of that first
     746              :   // token should be skipped).
     747              :   tl::expected<std::unique_ptr<AST::IfExpr>, Parse::Error::Node>
     748              :   parse_if_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     749              :                  location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     750              :   tl::expected<std::unique_ptr<AST::IfLetExpr>, Parse::Error::Node>
     751              :   parse_if_let_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     752              :                      location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     753              :   tl::expected<std::unique_ptr<AST::LoopExpr>, Parse::Error::Node>
     754              :   parse_loop_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     755              :                    tl::optional<AST::LoopLabel> label = tl::nullopt,
     756              :                    location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     757              :   tl::expected<std::unique_ptr<AST::WhileLoopExpr>, Parse::Error::Node>
     758              :   parse_while_loop_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     759              :                          tl::optional<AST::LoopLabel> label = tl::nullopt,
     760              :                          location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     761              :   tl::expected<std::unique_ptr<AST::WhileLetLoopExpr>, Parse::Error::Node>
     762              :   parse_while_let_loop_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     763            8 :                              tl::optional<AST::LoopLabel> label = tl::nullopt);
     764              :   tl::expected<std::unique_ptr<AST::ForLoopExpr>, Parse::Error::Node>
     765              :   parse_for_loop_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     766              :                        tl::optional<AST::LoopLabel> label = tl::nullopt);
     767              :   tl::expected<std::unique_ptr<AST::MatchExpr>, Parse::Error::Node>
     768              :   parse_match_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     769              :                     location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     770              :   AST::MatchArm parse_match_arm ();
     771              :   std::unique_ptr<AST::Pattern> parse_match_arm_pattern (TokenId end_token_id);
     772              :   tl::expected<std::unique_ptr<AST::Expr>, Parse::Error::Node>
     773              :   parse_labelled_loop_expr (const_TokenPtr tok,
     774              :                             AST::AttrVec outer_attrs = AST::AttrVec ());
     775              :   tl::expected<AST::LoopLabel, Parse::Error::LoopLabel>
     776              :   parse_loop_label (const_TokenPtr tok);
     777              :   tl::expected<std::unique_ptr<AST::AsyncBlockExpr>, Parse::Error::Node>
     778              :   parse_async_block_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
     779              :   tl::expected<std::unique_ptr<AST::GroupedExpr>, Parse::Error::Node>
     780              :   parse_grouped_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
     781              :   tl::expected<std::unique_ptr<AST::ClosureExpr>, Parse::Error::Node>
     782              :   parse_closure_expr (AST::AttrVec outer_attrs = AST::AttrVec ());
     783              :   AST::ClosureParam parse_closure_param ();
     784              : 
     785              :   tl::expected<std::unique_ptr<AST::BoxExpr>, Parse::Error::Node>
     786              :   parse_box_expr (AST::AttrVec outer_attrs,
     787              :                   location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     788              :   // When given a pratt_parsed_loc, use it as the location of the
     789              :   // first token parsed in the expression (the parsing of that first
     790              :   // token should be skipped).
     791              :   tl::expected<std::unique_ptr<AST::ReturnExpr>, Parse::Error::Node>
     792              :   parse_return_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     793              :                      location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     794              :   tl::expected<std::unique_ptr<AST::TryExpr>, Parse::Error::Node>
     795              :   parse_try_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     796              :                   location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     797              :   tl::expected<std::unique_ptr<AST::BreakExpr>, Parse::Error::Node>
     798              :   parse_break_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     799              :                     location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     800              :   std::unique_ptr<AST::ContinueExpr>
     801              :   parse_continue_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     802              :                        location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     803              :   tl::expected<std::unique_ptr<AST::UnsafeBlockExpr>, Parse::Error::Node>
     804              :   parse_unsafe_block_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     805              :                            location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     806              :   tl::expected<std::unique_ptr<AST::ArrayExpr>, Parse::Error::Node>
     807              :   parse_array_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     808              :                     location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     809              :   tl::expected<std::unique_ptr<AST::ExprWithoutBlock>, Parse::Error::Node>
     810              :   parse_grouped_or_tuple_expr (AST::AttrVec outer_attrs = AST::AttrVec (),
     811              :                                location_t pratt_parsed_loc = UNKNOWN_LOCATION);
     812              :   tl::expected<std::unique_ptr<AST::StructExprField>,
     813              :                Parse::Error::StructExprField>
     814              :   parse_struct_expr_field ();
     815              :   bool will_be_expr_with_block ();
     816              : 
     817              :   // Type-related
     818              :   std::unique_ptr<AST::TypeNoBounds> parse_type_no_bounds ();
     819              :   std::unique_ptr<AST::TypeNoBounds> parse_slice_or_array_type ();
     820              :   std::unique_ptr<AST::RawPointerType> parse_raw_pointer_type ();
     821              :   std::unique_ptr<AST::ReferenceType>
     822              :   parse_reference_type_inner (location_t locus);
     823              :   std::unique_ptr<AST::ReferenceType> parse_reference_type ();
     824              :   std::unique_ptr<AST::BareFunctionType>
     825              :   parse_bare_function_type (std::vector<AST::LifetimeParam> for_lifetimes);
     826              :   std::unique_ptr<AST::Type> parse_paren_prefixed_type ();
     827              :   std::unique_ptr<AST::TypeNoBounds> parse_paren_prefixed_type_no_bounds ();
     828              :   std::unique_ptr<AST::Type> parse_for_prefixed_type ();
     829              :   AST::MaybeNamedParam parse_maybe_named_param (AST::AttrVec outer_attrs);
     830              : 
     831              :   // Statement-related
     832              : 
     833              :   /**
     834              :    *Parse a let-statement
     835              :    * LetStatement :
     836              :    *    OuterAttribute*
     837              :    *            'let' PatternNoTopAlt ( ':' Type )? ('=' Expression )? ';'
     838              :    *
     839              :    * @param allow_no_semi Allow parsing a let-statement without expecting a
     840              :    *            semicolon to follow it
     841              :    */
     842              :   std::unique_ptr<AST::LetStmt> parse_let_stmt (AST::AttrVec outer_attrs,
     843              :                                                 ParseRestrictions restrictions
     844              :                                                 = ParseRestrictions ());
     845              :   std::unique_ptr<AST::Stmt> parse_expr_stmt (AST::AttrVec outer_attrs,
     846              :                                               ParseRestrictions restrictions
     847              :                                               = ParseRestrictions ());
     848              :   tl::expected<ExprOrStmt, Parse::Error::Node> parse_stmt_or_expr ();
     849              : 
     850              :   // Pattern-related
     851              :   std::unique_ptr<AST::Pattern> parse_literal_or_range_pattern ();
     852              :   std::unique_ptr<AST::RangePatternBound> parse_range_pattern_bound ();
     853              :   std::unique_ptr<AST::ReferencePattern> parse_reference_pattern ();
     854              :   std::unique_ptr<AST::Pattern> parse_grouped_or_tuple_pattern ();
     855              :   std::unique_ptr<AST::SlicePattern> parse_slice_pattern ();
     856              :   std::unique_ptr<AST::Pattern> parse_ident_leading_pattern ();
     857              :   std::unique_ptr<AST::TupleStructItems> parse_tuple_struct_items ();
     858              :   AST::StructPatternElements parse_struct_pattern_elems ();
     859              :   std::unique_ptr<AST::StructPatternField> parse_struct_pattern_field ();
     860              :   std::unique_ptr<AST::StructPatternField>
     861              :   parse_struct_pattern_field_partial (AST::AttrVec outer_attrs);
     862              : 
     863              :   int left_binding_power (const_TokenPtr token);
     864              : 
     865              :   bool done_end ();
     866              :   bool done_end_or_else ();
     867              :   bool done_end_of_file ();
     868              : 
     869         2239 :   void add_error (Error error) { error_table.push_back (std::move (error)); }
     870              : 
     871            4 :   void collect_potential_gating_error (Feature::Name feature, Error error)
     872              :   {
     873            4 :     Features::EarlyFeatureGateStore::get ().add (feature, error);
     874            4 :   }
     875              : 
     876              : public:
     877              :   // Construct parser with specified "managed" token source.
     878        21850 :   Parser (ManagedTokenSource &tokenSource) : lexer (tokenSource) {}
     879              : 
     880              :   // Parse items without parsing an entire crate. This function is the main
     881              :   // parsing loop of AST::Crate::parse_crate().
     882              :   tl::expected<std::vector<std::unique_ptr<AST::Item>>, Parse::Error::Items>
     883              :   parse_items ();
     884              : 
     885              :   // Main entry point for parser.
     886              :   std::unique_ptr<AST::Crate> parse_crate ();
     887              : 
     888              :   void debug_dump_ast_output (AST::Crate &crate, std::ostream &out);
     889              : 
     890              :   // Returns whether any parsing errors have occurred.
     891        10607 :   bool has_errors () const { return !error_table.empty (); }
     892              :   // Remove all parsing errors from the table
     893         1721 :   void clear_errors () { error_table.clear (); }
     894              : 
     895              :   // Get a reference to the list of errors encountered
     896         1708 :   std::vector<Error> &get_errors () { return error_table; }
     897              : 
     898              :   std::vector<std::pair<Feature::Name, Error>> &
     899            0 :   get_potential_feature_gate_errors ()
     900              :   {
     901            0 :     return gating_errors;
     902              :   }
     903              : 
     904         8145 :   const ManagedTokenSource &get_token_source () const { return lexer; }
     905              : 
     906        18256 :   const_TokenPtr peek_current_token () { return lexer.peek_token (0); }
     907            0 :   const_TokenPtr peek (int n) { return lexer.peek_token (n); }
     908              : 
     909              : private:
     910              :   // The token source (usually lexer) associated with the parser.
     911              :   ManagedTokenSource &lexer;
     912              :   // The error list.
     913              :   std::vector<Error> error_table;
     914              : 
     915              :   std::vector<std::pair<Feature::Name, Error>> gating_errors;
     916              :   // The names of inline modules while parsing.
     917              :   std::vector<std::string> inline_module_stack;
     918              : 
     919              :   class InlineModuleStackScope
     920              :   {
     921              :   private:
     922              :     Parser &parser;
     923              : 
     924              :   public:
     925         1235 :     InlineModuleStackScope (Parser &parser, std::string name) : parser (parser)
     926              :     {
     927         1235 :       parser.inline_module_stack.emplace_back (std::move (name));
     928            0 :     }
     929         1235 :     ~InlineModuleStackScope () { parser.inline_module_stack.pop_back (); }
     930              :   };
     931              : 
     932              :   // don't want to make things *only* AttributeParser uses public
     933              :   // TODO: fold more of AttributeParser into Parser?
     934              :   friend struct ::Rust::AST::AttributeParser;
     935              : };
     936              : 
     937              : std::string extract_module_path (const AST::AttrVec &inner_attrs,
     938              :                                  const AST::AttrVec &outer_attrs,
     939              :                                  const std::string &name);
     940              : 
     941              : /**
     942              :  * Check if a MacroMatch is allowed to follow the last parsed MacroMatch.
     943              :  *
     944              :  * @param last_match Last matcher parsed before the current match
     945              :  * @param match Current matcher to check
     946              :  *
     947              :  * @return true if the follow-up is valid, false otherwise
     948              :  */
     949              : bool is_match_compatible (const AST::MacroMatch &last_match,
     950              :                           const AST::MacroMatch &current_match);
     951              : } // namespace Rust
     952              : 
     953              : #endif // RUST_PARSE_H
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.