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