diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-09-12 14:47:58 +0800 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:21 +0000 |
commit | 2f7007a777bbb3d2fbd29f66b98d71ba6849eab6 (patch) | |
tree | 24600d3b090ae5b606f3b69688fa2fb32a351351 | |
parent | e0db6e13f05fb197621eca65d275094f2502473f (diff) | |
download | gcc-2f7007a777bbb3d2fbd29f66b98d71ba6849eab6.zip gcc-2f7007a777bbb3d2fbd29f66b98d71ba6849eab6.tar.gz gcc-2f7007a777bbb3d2fbd29f66b98d71ba6849eab6.tar.bz2 |
Attempt to fix the ExprWithoutBlock in ExprStmtWithoutBlock issue
First step toward consolidation of similar parsing functions (ComparisonExpr in this case)
Debug output for apparent parsing failure
Attempt to fix problem with non-digit character after 0 being mistaken as
non-decimal int literal
Attempt to fix incorrect tokenisation of a dot then a decimal
Try new implementation of token splitting rather than token replacing
-rw-r--r-- | gcc/rust/ast/rust-stmt.h | 21 | ||||
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 23 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 189 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse.h | 84 |
4 files changed, 191 insertions, 126 deletions
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h index 89b4d87..ce7a37a 100644 --- a/gcc/rust/ast/rust-stmt.h +++ b/gcc/rust/ast/rust-stmt.h @@ -120,31 +120,36 @@ protected: class ExprStmtWithoutBlock : public ExprStmt { public: - // ExprWithoutBlock* expr; + // TODO: ensure that this works + std::unique_ptr<ExprWithoutBlock> expr; /* HACK: cannot ensure type safety of ExprWithoutBlock due to Pratt parsing, * so have to store more general type of Expr. FIXME: fix this issue somehow * or redesign AST. */ - // std::unique_ptr<ExprWithoutBlock> expr; - std::unique_ptr<Expr> expr; + // std::unique_ptr<Expr> expr; std::string as_string () const override; - // ExprStmtWithoutBlock(std::unique_ptr<ExprWithoutBlock> expr) : - // expr(std::move(expr)) {} - ExprStmtWithoutBlock (std::unique_ptr<Expr> expr, Location locus) + ExprStmtWithoutBlock (std::unique_ptr<ExprWithoutBlock> expr, Location locus) : ExprStmt (locus), expr (std::move (expr)) {} + /*ExprStmtWithoutBlock (std::unique_ptr<Expr> expr, Location locus) + : ExprStmt (locus), expr (std::move (expr)) + {}*/ // Copy constructor with clone ExprStmtWithoutBlock (ExprStmtWithoutBlock const &other) - : ExprStmt (other), expr (other.expr->clone_expr /*_without_block*/ ()) + : ExprStmt (other), expr (other.expr->clone_expr_without_block ()) {} + /*ExprStmtWithoutBlock (ExprStmtWithoutBlock const &other) + : ExprStmt (other), expr (other.expr->clone_expr ()) + {}*/ // Overloaded assignment operator to clone ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock const &other) { ExprStmt::operator= (other); - expr = other.expr->clone_expr /*_without_block*/ (); + expr = other.expr->clone_expr_without_block (); + //expr = other.expr->clone_expr (); return *this; } diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 632d5fe..019e922 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -95,6 +95,12 @@ is_whitespace (char character) return ISSPACE (character); } +bool +is_non_decimal_int_literal_separator (char character) +{ + return character == 'x' || character == 'o' || character == 'b'; +} + // this compiles fine, so any intellisense saying otherwise is fake news Lexer::Lexer (const char *filename, RAIIFile file_input, Linemap *linemap) : input (std::move (file_input)), current_line (1), current_column (1), @@ -674,10 +680,11 @@ Lexer::build_token () return Token::make (DOT_DOT, loc); } } - else if (!ISDIGIT (peek_input ())) + else /*if (!ISDIGIT (peek_input ()))*/ { // single dot . - // Only if followed by a non-number - otherwise is float + // Only if followed by a non-number - otherwise is float + // nope, float cannot start with '.'. current_column++; return Token::make (DOT, loc); } @@ -721,9 +728,9 @@ Lexer::build_token () return parse_identifier_or_keyword (loc); // int and float literals - if (ISDIGIT (current_char) || current_char == '.') + if (ISDIGIT (current_char)) { // _ not allowed as first char - if (current_char == '0' && !ISDIGIT (peek_input ())) + if (current_char == '0' && is_non_decimal_int_literal_separator (peek_input ())) { // handle binary, octal, hex literals TokenPtr non_dec_int_lit_ptr @@ -752,6 +759,14 @@ Lexer::build_token () return char_or_lifetime_ptr; } + // DEBUG: check for specific character problems: + if (current_char == '0') + fprintf(stderr, "'0' uncaught before unexpected character\n"); + else if (current_char == ']') + fprintf(stderr, "']' uncaught before unexpected character\n"); + else if (current_char == 0x5d) + fprintf(stderr, "whatever 0x5d is (not '0' or ']') uncaught before unexpected character\n"); + // didn't match anything so error rust_error_at (loc, "unexpected character '%x'", current_char); current_column++; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 1e30047..6a9b45a 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -191,20 +191,21 @@ Parser<ManagedTokenSource>::skip_generics_right_angle () lexer.skip_token (); return true; case RIGHT_SHIFT: { +#if 0 /* shit. preferred HACK would be to replace this token in stream with * '>', but may not be possible at this point. */ // FIXME: ensure locations aren't messed up TokenPtr right_angle = Token::make (RIGHT_ANGLE, tok->get_locus () + 1); lexer.replace_current_token (right_angle); +#endif // new implementation that should be better -#if 0 lexer.split_current_token (RIGHT_ANGLE, RIGHT_ANGLE); lexer.skip_token (); -#endif return true; } case GREATER_OR_EQUAL: { +#if 0 // another HACK - replace with equal (as assignment intended, probably) /* FIXME: is this even required? how many people wouldn't leave a space? * - apparently rustc has this feature */ @@ -212,14 +213,15 @@ Parser<ManagedTokenSource>::skip_generics_right_angle () TokenPtr equal = Token::make (EQUAL, tok->get_locus () + 1); lexer.replace_current_token (equal); return true; +#endif // new implementation that should be better -#if 0 lexer.split_current_token (RIGHT_ANGLE, EQUAL); lexer.skip_token (); -#endif + return true; } case RIGHT_SHIFT_EQ: { +#if 0 // another HACK - replace with greater or equal // FIXME: again, is this really required? rustc has the feature, though // FIXME: ensure locations aren't messed up @@ -227,12 +229,12 @@ Parser<ManagedTokenSource>::skip_generics_right_angle () = Token::make (GREATER_OR_EQUAL, tok->get_locus () + 1); lexer.replace_current_token (greater_equal); return true; +#endif // new implementation that should be better -#if 0 lexer.split_current_token (RIGHT_ANGLE, GREATER_OR_EQUAL); lexer.skip_token (); -#endif + return true; } default: rust_error_at (tok->get_locus (), @@ -255,8 +257,8 @@ Parser<ManagedTokenSource>::left_binding_power (const_TokenPtr token) switch (token->get_id ()) { /* TODO: issue here - distinguish between method calls and field access - * somehow? Also would have to distinguish between paths and function - * calls (:: operator), maybe more stuff. */ + * somehow? Also would have to distinguish between paths and function + * calls (:: operator), maybe more stuff. */ /* Current plan for tackling LBP - don't do it based on token, use * lookahead. Or alternatively, only use Pratt parsing for OperatorExpr * and handle other expressions without it. rustc only considers @@ -6461,16 +6463,7 @@ Parser<ManagedTokenSource>::parse_expr_stmt_without_block ( /* TODO: maybe move more logic for expr without block in here for better error * handling */ - // try to parse expr without block - /*AST::ExprWithoutBlock* expr = nullptr; - expr = parse_expr_without_block(std::move(outer_attrs));*/ - // HACK: parse expression instead of expression without block, due to Pratt - // parsing issues - /*std::unique_ptr<AST::Expr> expr = nullptr; - Location locus = lexer.peek_token ()->get_locus (); - expr = parse_expr (std::move (outer_attrs));*/ - - // attempt to parse via parse_expr_without_block + // attempt to parse via parse_expr_without_block - seems to work std::unique_ptr<AST::ExprWithoutBlock> expr = nullptr; Location locus = lexer.peek_token ()->get_locus (); expr = parse_expr_without_block (std::move (outer_attrs)); @@ -10800,9 +10793,9 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr ( switch (t2->get_id ()) { case EXCLAM: { - // macro invocation or macro invocation semi - depends on whether there - // is a final ';' convert path in expr to simple path (as that is used - // in macros) + /* macro invocation or macro invocation semi - depends on whether there + * is a final ';' */ + // convert path in expr to simple path (as that is used in macros) AST::SimplePath macro_path = path.as_simple_path (); if (macro_path.is_empty ()) { @@ -10854,8 +10847,7 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr ( rust_error_at ( t3->get_locus (), "failed to parse token tree for macro invocation (or semi) - " - "found " - "'%s'", + "found '%s'", t3->get_token_description ()); return ExprOrStmt::create_error (); } @@ -10967,8 +10959,8 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr ( return ExprOrStmt (std::move (expr)); } case LEFT_PAREN: { - // assume struct expr tuple (as struct-enum disambiguation requires name - // lookup) again, make statement if final ';' + /* assume struct expr tuple (as struct-enum disambiguation requires name + * lookup) again, make statement if final ';' */ std::unique_ptr<AST::CallExpr> struct_expr = parse_struct_expr_tuple_partial (std::move (path), std::move (outer_attrs)); @@ -11022,9 +11014,6 @@ template <typename ManagedTokenSource> std::unique_ptr<AST::StructExprField> Parser<ManagedTokenSource>::parse_struct_expr_field () { - // DEBUG: - fprintf (stderr, "beginning struct/enum expr field parsing \n"); - const_TokenPtr t = lexer.peek_token (); switch (t->get_id ()) { @@ -11045,11 +11034,6 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () return nullptr; } - // DEBUG: - fprintf ( - stderr, - "struct/enum expr field parsing field identifier value done \n"); - return std::unique_ptr<AST::StructExprFieldIdentifierValue> ( new AST::StructExprFieldIdentifierValue (std::move (ident), std::move (expr))); @@ -11060,10 +11044,6 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () Identifier ident = t->get_str (); lexer.skip_token (); - // DEBUG: - fprintf (stderr, - "struct/enum expr field parsing field identifier done \n"); - return std::unique_ptr<AST::StructExprFieldIdentifier> ( new AST::StructExprFieldIdentifier (std::move (ident))); } @@ -11088,30 +11068,18 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () return nullptr; } - // DEBUG: - fprintf (stderr, - "struct/enum expr field parsing field index value done \n"); - return std::unique_ptr<AST::StructExprFieldIndexValue> ( new AST::StructExprFieldIndexValue (index, std::move (expr))); } case DOT_DOT: - // this is a struct base and can't be parsed here, so just return nothing - // without erroring - - // DEBUG: - fprintf (stderr, "struct/enum expr field parsing failed - '..' \n"); + /* this is a struct base and can't be parsed here, so just return nothing + * without erroring */ return nullptr; default: - // DEBUG: - fprintf (stderr, - "struct/enum expr field parsing failed - unrecognised char \n"); - rust_error_at (t->get_locus (), "unrecognised token '%s' as first token of struct expr " - "field - expected identifier " - "or int literal", + "field - expected identifier or int literal", t->get_token_description ()); return nullptr; } @@ -11194,9 +11162,8 @@ Parser<ManagedTokenSource>::parse_macro_invocation_maybe_semi ( /* with curly bracketed macros, assume it is a macro invocation unless * a semicolon is explicitly put at the end. this is not necessarily * true (i.e. context-dependence) and so may have to be fixed up via - * HACKs in semantic - * analysis (by checking whether it is the last elem in the vector). - */ + * HACKs in semantic analysis (by checking whether it is the last elem in + * the vector). */ if (lexer.peek_token ()->get_id () == SEMICOLON) { @@ -11399,8 +11366,7 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power, // parse null denotation (unary part of expression) std::unique_ptr<AST::Expr> expr - = null_denotation (current_token, std::move (outer_attrs), - restrictions); + = null_denotation (current_token, std::move (outer_attrs), restrictions); if (expr == nullptr) { @@ -11720,7 +11686,8 @@ Parser<ManagedTokenSource>::null_denotation ( // HACK: as struct expressions should always be value expressions, // cannot be referenced - ParseRestrictions entered_from_unary = { .can_be_struct_expr = false, .entered_from_unary = true }; + ParseRestrictions entered_from_unary + = {.can_be_struct_expr = false, .entered_from_unary = true}; /*entered_from_unary.entered_from_unary = true; entered_from_unary.can_be_struct_expr = false;*/ @@ -11786,8 +11753,8 @@ Parser<ManagedTokenSource>::null_denotation ( fprintf (stderr, "beginning null denotation " "self/self-alias/dollar/crate/super handling\n"); - // best option: parse as path, then extract identifier, macro, - // struct/enum, or just path info from it + /* best option: parse as path, then extract identifier, macro, + * struct/enum, or just path info from it */ AST::PathInExpression path = parse_path_in_expression_pratt (tok); // DEBUG @@ -11956,33 +11923,55 @@ Parser<ManagedTokenSource>::left_denotation ( std::move (outer_attrs), restrictions); case EQUAL_EQUAL: // equal to expression - binary infix (no associativity) - return parse_binary_equal_expr (tok, std::move (left), - std::move (outer_attrs), restrictions); + /*return parse_binary_equal_expr (tok, std::move (left), + std::move (outer_attrs), restrictions);*/ + return parse_comparison_expr (tok, std::move (left), + std::move (outer_attrs), + AST::ComparisonExpr::ExprType::EQUAL, + restrictions); case NOT_EQUAL: // not equal to expression - binary infix (no associativity) - return parse_binary_not_equal_expr (tok, std::move (left), + /*return parse_binary_not_equal_expr (tok, std::move (left), std::move (outer_attrs), - restrictions); + restrictions);*/ + return parse_comparison_expr (tok, std::move (left), + std::move (outer_attrs), + AST::ComparisonExpr::ExprType::NOT_EQUAL, + restrictions); case RIGHT_ANGLE: // greater than expression - binary infix (no associativity) - return parse_binary_greater_than_expr (tok, std::move (left), + /*return parse_binary_greater_than_expr (tok, std::move (left), std::move (outer_attrs), - restrictions); + restrictions);*/ + return parse_comparison_expr (tok, std::move (left), + std::move (outer_attrs), + AST::ComparisonExpr::ExprType::GREATER_THAN, + restrictions); case LEFT_ANGLE: // less than expression - binary infix (no associativity) - return parse_binary_less_than_expr (tok, std::move (left), + /*return parse_binary_less_than_expr (tok, std::move (left), std::move (outer_attrs), - restrictions); + restrictions);*/ + return parse_comparison_expr (tok, std::move (left), + std::move (outer_attrs), + AST::ComparisonExpr::ExprType::LESS_THAN, + restrictions); case GREATER_OR_EQUAL: // greater than or equal to expression - binary infix (no associativity) - return parse_binary_greater_equal_expr (tok, std::move (left), + /*return parse_binary_greater_equal_expr (tok, std::move (left), std::move (outer_attrs), - restrictions); + restrictions);*/ + return parse_comparison_expr ( + tok, std::move (left), std::move (outer_attrs), + AST::ComparisonExpr::ExprType::GREATER_OR_EQUAL, restrictions); case LESS_OR_EQUAL: // less than or equal to expression - binary infix (no associativity) - return parse_binary_less_equal_expr (tok, std::move (left), + /*return parse_binary_less_equal_expr (tok, std::move (left), std::move (outer_attrs), - restrictions); + restrictions);*/ + return parse_comparison_expr ( + tok, std::move (left), std::move (outer_attrs), + AST::ComparisonExpr::ExprType::LESS_OR_EQUAL, restrictions); case OR: // lazy logical or expression - binary infix return parse_lazy_or_expr (tok, std::move (left), std::move (outer_attrs), @@ -12093,8 +12082,8 @@ Parser<ManagedTokenSource>::left_denotation ( && lexer.peek_token (1)->get_id () != LEFT_PAREN && lexer.peek_token (1)->get_id () != SCOPE_RESOLUTION) { - // field expression (or should be) - FIXME: scope resolution right - // after identifier should always be method, I'm pretty sure + /* field expression (or should be) - FIXME: scope resolution right + * after identifier should always be method, I'm pretty sure */ return parse_field_access_expr (tok, std::move (left), std::move (outer_attrs), restrictions); @@ -12362,6 +12351,58 @@ Parser<ManagedTokenSource>::parse_right_shift_expr ( locus)); } +/* Returns the left binding power for the given ComparisonExpr type. + * TODO make constexpr? Would that even do anything useful? */ +inline binding_powers +get_lbp_for_comparison_expr (AST::ComparisonExpr::ExprType expr_type) +{ + switch (expr_type) + { + case AST::ComparisonExpr::EQUAL: + return LBP_EQUAL; + case AST::ComparisonExpr::NOT_EQUAL: + return LBP_NOT_EQUAL; + case AST::ComparisonExpr::GREATER_THAN: + return LBP_GREATER_THAN; + case AST::ComparisonExpr::LESS_THAN: + return LBP_SMALLER_THAN; + case AST::ComparisonExpr::GREATER_OR_EQUAL: + return LBP_GREATER_EQUAL; + case AST::ComparisonExpr::LESS_OR_EQUAL: + return LBP_SMALLER_EQUAL; + default: + // WTF? should not happen, this is an error + rust_error_at ( + Location (), + "could not get LBP for ComparisonExpr - unknown ExprType!"); + return LBP_EQUAL; + } +} + +/* Parses a ComparisonExpr of given type and LBP. TODO find a way to only + * specify one and have the other looked up - e.g. specify ExprType and binding + * power is looked up? */ +template <typename ManagedTokenSource> +std::unique_ptr<AST::ComparisonExpr> +Parser<ManagedTokenSource>::parse_comparison_expr ( + const_TokenPtr, std::unique_ptr<AST::Expr> left, std::vector<AST::Attribute>, + AST::ComparisonExpr::ExprType expr_type, ParseRestrictions restrictions) +{ + // parse RHS (as tok has already been consumed in parse_expression) + std::unique_ptr<AST::Expr> right + = parse_expr (get_lbp_for_comparison_expr (expr_type), + std::vector<AST::Attribute> (), restrictions); + if (right == nullptr) + return nullptr; + + // TODO: check types. actually, do so during semantic analysis + Location locus = left->get_locus_slow (); + + return std::unique_ptr<AST::ComparisonExpr> ( + new AST::ComparisonExpr (std::move (left), std::move (right), expr_type, + locus)); +} + // Parses a binary equal to expression (with Pratt parsing). template <typename ManagedTokenSource> std::unique_ptr<AST::ComparisonExpr> diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 2cf503a..cec0904 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -28,7 +28,8 @@ struct ExprOrStmt // Returns whether this object is in an error state. bool is_error () const { - return (expr == nullptr && stmt == nullptr) || (expr != nullptr && stmt != nullptr); + return (expr == nullptr && stmt == nullptr) + || (expr != nullptr && stmt != nullptr); } // Returns an error state object. @@ -69,8 +70,7 @@ struct ParseRestrictions // Parser implementation for gccrs. // TODO: if updated to C++20, ManagedTokenSource would be useful as a concept -template <typename ManagedTokenSource> -class Parser +template <typename ManagedTokenSource> class Parser { private: void skip_after_semicolon (); @@ -126,7 +126,7 @@ private: std::unique_ptr<AST::MacroMatchRepetition> parse_macro_match_repetition (); // Top-level item-related - std::vector< std::unique_ptr<AST::Item> > parse_items (); + std::vector<std::unique_ptr<AST::Item> > parse_items (); std::unique_ptr<AST::Item> parse_item (bool called_from_statement); std::unique_ptr<AST::VisItem> parse_vis_item (std::vector<AST::Attribute> outer_attrs); @@ -141,21 +141,18 @@ private: parse_extern_crate (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); std::unique_ptr<AST::UseDeclaration> - parse_use_decl (AST::Visibility vis, - std::vector<AST::Attribute> outer_attrs); + parse_use_decl (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); std::unique_ptr<AST::UseTree> parse_use_tree (); std::unique_ptr<AST::Function> - parse_function (AST::Visibility vis, - std::vector<AST::Attribute> outer_attrs); + parse_function (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); AST::FunctionQualifiers parse_function_qualifiers (); - std::vector< std::unique_ptr<AST::GenericParam> > + std::vector<std::unique_ptr<AST::GenericParam> > parse_generic_params_in_angles (); - std::vector< std::unique_ptr<AST::GenericParam> > parse_generic_params (); - std::vector< std::unique_ptr<AST::LifetimeParam> > - parse_lifetime_params (); + std::vector<std::unique_ptr<AST::GenericParam> > parse_generic_params (); + std::vector<std::unique_ptr<AST::LifetimeParam> > parse_lifetime_params (); std::vector<AST::LifetimeParam> parse_lifetime_params_objs (); AST::LifetimeParam parse_lifetime_param (); - std::vector< std::unique_ptr<AST::TypeParam> > parse_type_params (); + std::vector<std::unique_ptr<AST::TypeParam> > parse_type_params (); std::unique_ptr<AST::TypeParam> parse_type_param (); std::vector<AST::FunctionParam> parse_function_params (); AST::FunctionParam parse_function_param (); @@ -167,8 +164,7 @@ private: std::unique_ptr<AST::TypeBoundWhereClauseItem> parse_type_bound_where_clause_item (); std::vector<AST::LifetimeParam> parse_for_lifetimes (); - std::vector< std::unique_ptr<AST::TypeParamBound> > - parse_type_param_bounds (); + std::vector<std::unique_ptr<AST::TypeParamBound> > parse_type_param_bounds (); std::unique_ptr<AST::TypeParamBound> parse_type_param_bound (); std::unique_ptr<AST::TraitBound> parse_trait_bound (); std::vector<AST::Lifetime> parse_lifetime_bounds (); @@ -184,7 +180,7 @@ private: AST::TupleField parse_tuple_field (); std::unique_ptr<AST::Enum> parse_enum (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); - std::vector< std::unique_ptr<AST::EnumItem> > parse_enum_items (); + std::vector<std::unique_ptr<AST::EnumItem> > parse_enum_items (); std::unique_ptr<AST::EnumItem> parse_enum_item (); std::unique_ptr<AST::Union> parse_union (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); @@ -209,8 +205,9 @@ private: parse_inherent_impl_function_or_method ( AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); std::unique_ptr<AST::TraitImplItem> parse_trait_impl_item (); - std::unique_ptr<AST::TraitImplItem> parse_trait_impl_function_or_method ( - AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); + std::unique_ptr<AST::TraitImplItem> + parse_trait_impl_function_or_method (AST::Visibility vis, + std::vector<AST::Attribute> outer_attrs); std::unique_ptr<AST::ExternBlock> parse_extern_block (AST::Visibility vis, std::vector<AST::Attribute> outer_attrs); @@ -219,20 +216,20 @@ private: AST::Method parse_method (); // Expression-related (Pratt parsed) - std::unique_ptr<AST::Expr> - parse_expr (std::vector<AST::Attribute> outer_attrs - = std::vector<AST::Attribute> (), - ParseRestrictions restrictions = ParseRestrictions ()); - std::unique_ptr<AST::Expr> - parse_expr (int right_binding_power, - std::vector<AST::Attribute> outer_attrs - = std::vector<AST::Attribute> (), - ParseRestrictions restrictions = ParseRestrictions ()); + std::unique_ptr<AST::Expr> parse_expr (std::vector<AST::Attribute> outer_attrs + = std::vector<AST::Attribute> (), + ParseRestrictions restrictions + = ParseRestrictions ()); + std::unique_ptr<AST::Expr> parse_expr (int right_binding_power, + std::vector<AST::Attribute> outer_attrs + = std::vector<AST::Attribute> (), + ParseRestrictions restrictions + = ParseRestrictions ()); std::unique_ptr<AST::Expr> null_denotation (const_TokenPtr t, - std::vector<AST::Attribute> outer_attrs - = std::vector<AST::Attribute> (), - ParseRestrictions restrictions = ParseRestrictions ()); + std::vector<AST::Attribute> outer_attrs + = std::vector<AST::Attribute> (), + ParseRestrictions restrictions = ParseRestrictions ()); std::unique_ptr<AST::Expr> left_denotation (const_TokenPtr t, std::unique_ptr<AST::Expr> left, std::vector<AST::Attribute> outer_attrs @@ -243,10 +240,11 @@ private: std::vector<AST::Attribute> outer_attrs, ParseRestrictions restrictions = ParseRestrictions ()); - std::unique_ptr<AST::ArithmeticOrLogicalExpr> parse_binary_minus_expr ( - const_TokenPtr tok, std::unique_ptr<AST::Expr> left, - std::vector<AST::Attribute> outer_attrs, - ParseRestrictions restrictions = ParseRestrictions ()); + std::unique_ptr<AST::ArithmeticOrLogicalExpr> + parse_binary_minus_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left, + std::vector<AST::Attribute> outer_attrs, + ParseRestrictions restrictions + = ParseRestrictions ()); std::unique_ptr<AST::ArithmeticOrLogicalExpr> parse_binary_mult_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left, std::vector<AST::Attribute> outer_attrs, @@ -283,10 +281,16 @@ private: std::vector<AST::Attribute> outer_attrs, ParseRestrictions restrictions = ParseRestrictions ()); - std::unique_ptr<AST::ComparisonExpr> parse_binary_equal_expr ( - const_TokenPtr tok, std::unique_ptr<AST::Expr> left, - std::vector<AST::Attribute> outer_attrs, - ParseRestrictions restrictions = ParseRestrictions ()); + std::unique_ptr<AST::ComparisonExpr> + parse_comparison_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left, + std::vector<AST::Attribute> outer_attrs, + AST::ComparisonExpr::ExprType expr_type, + ParseRestrictions restrictions = ParseRestrictions ()); + std::unique_ptr<AST::ComparisonExpr> + parse_binary_equal_expr (const_TokenPtr tok, std::unique_ptr<AST::Expr> left, + std::vector<AST::Attribute> outer_attrs, + ParseRestrictions restrictions + = ParseRestrictions ()); std::unique_ptr<AST::ComparisonExpr> parse_binary_not_equal_expr ( const_TokenPtr tok, std::unique_ptr<AST::Expr> left, std::vector<AST::Attribute> outer_attrs, @@ -457,7 +461,7 @@ private: = std::vector<AST::Attribute> (), bool pratt_parse = false); AST::MatchArm parse_match_arm (); - std::vector< std::unique_ptr<AST::Pattern> > + std::vector<std::unique_ptr<AST::Pattern> > parse_match_arm_patterns (TokenId end_token_id); std::unique_ptr<AST::BaseLoopExpr> parse_labelled_loop_expr (std::vector<AST::Attribute> outer_attrs @@ -551,7 +555,7 @@ private: public: // Construct parser with specified "managed" token source. - Parser (ManagedTokenSource tokenSource) : lexer (std::move(tokenSource)) {} + Parser (ManagedTokenSource tokenSource) : lexer (std::move (tokenSource)) {} // Main entry point for parser. AST::Crate parse_crate (); |