<commit_before>use super::{Parser, PResult, PathStyle};

use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use crate::ptr::P;
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
use crate::parse::token::{self};
use crate::print::pprust;
use crate::source_map::{respan, Span, Spanned};
use crate::symbol::kw;
use crate::ThinVec;

use errors::{Applicability, DiagnosticBuilder};

type Expected = Option<&'static str>;

impl<'a> Parser<'a> {
    /// Parses a pattern.
    pub fn parse_pat(&mut self, expected: Expected) -> PResult<'a, P<Pat>> {
        self.parse_pat_with_range_pat(true, expected)
    }

    // FIXME(or_patterns, Centril | dlrobertson):
    // remove this and use `parse_top_pat` everywhere it is used instead.
    pub(super) fn parse_top_pat_unpack(&mut self, gate_or: bool) -> PResult<'a, Vec<P<Pat>>> {
        self.parse_top_pat(gate_or)
            .map(|pat| pat.and_then(|pat| match pat.node {
                PatKind::Or(pats) => pats,
                node => vec![self.mk_pat(pat.span, node)],
            }))
    }

    /// Entry point to the main pattern parser.
    /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
    pub(super) fn parse_top_pat(&mut self, gate_or: bool) -> PResult<'a, P<Pat>> {
        // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
        if self.eat_or_separator() && gate_or {
            self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
        }

        self.parse_pat_with_or(None, gate_or, true)<commit_msg>parser: document `parse_pat`.<commit_after>use super::{Parser, PResult, PathStyle};

use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use crate::ptr::P;
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
use crate::parse::token::{self};
use crate::print::pprust;
use crate::source_map::{respan, Span, Spanned};
use crate::symbol::kw;
use crate::ThinVec;

use errors::{Applicability, DiagnosticBuilder};

type Expected = Option<&'static str>;

impl<'a> Parser<'a> {
    /// Parses a pattern.
    ///
    /// Corresponds to `pat<no_top_alt>` in RFC 2535 and does not admit or-patterns
    /// at the top level. Used when parsing the parameters of lambda expressions,
    /// functions, function pointers, and `pat` macro fragments.
    pub fn parse_pat(&mut self, expected: Expected) -> PResult<'a, P<Pat>> {
        self.parse_pat_with_range_pat(true, expected)
    }

    // FIXME(or_patterns, Centril | dlrobertson):
    // remove this and use `parse_top_pat` everywhere it is used instead.
    pub(super) fn parse_top_pat_unpack(&mut self, gate_or: bool) -> PResult<'a, Vec<P<Pat>>> {
        self.parse_top_pat(gate_or)
            .map(|pat| pat.and_then(|pat| match pat.node {
                PatKind::Or(pats) => pats,
                node => vec![self.mk_pat(pat.span, node)],
            }))
    }

    /// Entry point to the main pattern parser.
    /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
    pub(super) fn parse_top_pat(&mut self, gate_or: bool) -> PResult<'a, P<Pat>> {
        // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
        if self.eat_or_separator() && gate_or {
            self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
        }

        self.parse_pat_with_or(None, gate_or, true)
{'fraction_non_alphanumeric': 0.1453732177802628, 'fraction_numerical': 0.010064299692479732, 'mean_word_length': 3.511979823455233, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5429710', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1214, 'n_words': 303}