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

Generated by: LCOV version 2.5.0-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.