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