mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Simplify
This commit is contained in:
		
							parent
							
								
									dd64a155e9
								
							
						
					
					
						commit
						cf7d4a2a24
					
				@ -41,6 +41,11 @@ Grammar(
 | 
				
			|||||||
        [">=", "GTEQ"],
 | 
					        [">=", "GTEQ"],
 | 
				
			||||||
        ["+=", "PLUSEQ"],
 | 
					        ["+=", "PLUSEQ"],
 | 
				
			||||||
        ["-=", "MINUSEQ"],
 | 
					        ["-=", "MINUSEQ"],
 | 
				
			||||||
 | 
					        ["|=", "PIPEEQ"],
 | 
				
			||||||
 | 
					        ["&=", "AMPEQ"],
 | 
				
			||||||
 | 
					        ["^=", "CARETEQ"],
 | 
				
			||||||
 | 
					        ["/=", "SLASHEQ"],
 | 
				
			||||||
 | 
					        ["*=", "STAREQ"],
 | 
				
			||||||
        ["&&", "AMPAMP"],
 | 
					        ["&&", "AMPAMP"],
 | 
				
			||||||
        ["||", "PIPEPIPE"],
 | 
					        ["||", "PIPEPIPE"],
 | 
				
			||||||
        ["<<", "SHL"],
 | 
					        ["<<", "SHL"],
 | 
				
			||||||
 | 
				
			|||||||
@ -45,35 +45,33 @@ enum Op {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn current_op(p: &Parser) -> (u8, Op) {
 | 
					fn current_op(p: &Parser) -> (u8, Op) {
 | 
				
			||||||
    if p.at_compound2(PLUS, EQ) {
 | 
					    if let Some(t) = p.next3() {
 | 
				
			||||||
        return (1, Op::Composite(PLUSEQ, 2));
 | 
					        match t {
 | 
				
			||||||
 | 
					            (L_ANGLE, L_ANGLE, EQ) =>
 | 
				
			||||||
 | 
					                return (1, Op::Composite(SHLEQ, 3)),
 | 
				
			||||||
 | 
					            (R_ANGLE, R_ANGLE, EQ) =>
 | 
				
			||||||
 | 
					                return (1, Op::Composite(SHREQ, 3)),
 | 
				
			||||||
 | 
					            _ => (),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    if p.at_compound2(MINUS, EQ) {
 | 
					 | 
				
			||||||
        return (1, Op::Composite(MINUSEQ, 2));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if p.at_compound3(L_ANGLE, L_ANGLE, EQ) {
 | 
					
 | 
				
			||||||
        return (1, Op::Composite(SHLEQ, 3));
 | 
					    if let Some(t) = p.next2() {
 | 
				
			||||||
 | 
					        match t {
 | 
				
			||||||
 | 
					            (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)),
 | 
				
			||||||
 | 
					            (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)),
 | 
				
			||||||
 | 
					            (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)),
 | 
				
			||||||
 | 
					            (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)),
 | 
				
			||||||
 | 
					            (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)),
 | 
				
			||||||
 | 
					            (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)),
 | 
				
			||||||
 | 
					            (CARET, EQ) => return (1, Op::Composite(CARETEQ, 2)),
 | 
				
			||||||
 | 
					            (PIPE, PIPE) => return (3, Op::Composite(PIPEPIPE, 2)),
 | 
				
			||||||
 | 
					            (AMP, AMP) => return (4, Op::Composite(AMPAMP, 2)),
 | 
				
			||||||
 | 
					            (L_ANGLE, EQ) => return (5, Op::Composite(LTEQ, 2)),
 | 
				
			||||||
 | 
					            (R_ANGLE, EQ) => return (5, Op::Composite(GTEQ, 2)),
 | 
				
			||||||
 | 
					            (L_ANGLE, L_ANGLE) => return (9, Op::Composite(SHL, 2)),
 | 
				
			||||||
 | 
					            (R_ANGLE, R_ANGLE) => return (9, Op::Composite(SHR, 2)),
 | 
				
			||||||
 | 
					            _ => (),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    if p.at_compound3(R_ANGLE, R_ANGLE, EQ) {
 | 
					 | 
				
			||||||
        return (1, Op::Composite(SHREQ, 3));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(PIPE, PIPE) {
 | 
					 | 
				
			||||||
        return (3, Op::Composite(PIPEPIPE, 2));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(AMP, AMP) {
 | 
					 | 
				
			||||||
        return (4, Op::Composite(AMPAMP, 2));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(L_ANGLE, EQ) {
 | 
					 | 
				
			||||||
        return (5, Op::Composite(LTEQ, 2));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(R_ANGLE, EQ) {
 | 
					 | 
				
			||||||
        return (5, Op::Composite(GTEQ, 2));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(L_ANGLE, L_ANGLE) {
 | 
					 | 
				
			||||||
        return (9, Op::Composite(SHL, 2));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if p.at_compound2(R_ANGLE, R_ANGLE) {
 | 
					 | 
				
			||||||
        return (9, Op::Composite(SHR, 2));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let bp = match p.current() {
 | 
					    let bp = match p.current() {
 | 
				
			||||||
 | 
				
			|||||||
@ -68,12 +68,12 @@ impl<'t> Parser<'t> {
 | 
				
			|||||||
        self.current() == kind
 | 
					        self.current() == kind
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub(crate) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool {
 | 
					    pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
 | 
				
			||||||
        self.0.at_compound2(c1, c2)
 | 
					        self.0.next2()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub(crate) fn at_compound3(&self, c1: SyntaxKind, c2: SyntaxKind, c3: SyntaxKind) -> bool {
 | 
					    pub(crate) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
 | 
				
			||||||
        self.0.at_compound3(c1, c2, c3)
 | 
					        self.0.next3()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Checks if the current token is contextual keyword with text `t`.
 | 
					    /// Checks if the current token is contextual keyword with text `t`.
 | 
				
			||||||
 | 
				
			|||||||
@ -65,15 +65,26 @@ impl<'t> ParserImpl<'t> {
 | 
				
			|||||||
        self.events
 | 
					        self.events
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub(super) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool {
 | 
					    pub(super) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
 | 
				
			||||||
        self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2
 | 
					        let c1 = self.inp.kind(self.pos);
 | 
				
			||||||
            && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos)
 | 
					        let c2 = self.inp.kind(self.pos + 1);
 | 
				
			||||||
 | 
					        if self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos) {
 | 
				
			||||||
 | 
					            Some((c1, c2))
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            None
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub(super) fn at_compound3(&self, c1: SyntaxKind, c2: SyntaxKind, c3: SyntaxKind) -> bool {
 | 
					    pub(super) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
 | 
				
			||||||
        self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2 && self.inp.kind(self.pos + 2) == c3
 | 
					        let c1 = self.inp.kind(self.pos);
 | 
				
			||||||
            && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos)
 | 
					        let c2 = self.inp.kind(self.pos + 1);
 | 
				
			||||||
            && self.inp.start(self.pos + 2) == self.inp.start(self.pos + 1) + self.inp.len(self.pos + 1)
 | 
					        let c3 = self.inp.kind(self.pos + 2);
 | 
				
			||||||
 | 
					        if self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos)
 | 
				
			||||||
 | 
					           && self.inp.start(self.pos + 2) == self.inp.start(self.pos + 1) + self.inp.len(self.pos + 1){
 | 
				
			||||||
 | 
					            Some((c1, c2, c3))
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            None
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub(super) fn nth(&self, n: u32) -> SyntaxKind {
 | 
					    pub(super) fn nth(&self, n: u32) -> SyntaxKind {
 | 
				
			||||||
 | 
				
			|||||||
@ -50,6 +50,11 @@ pub enum SyntaxKind {
 | 
				
			|||||||
    GTEQ,
 | 
					    GTEQ,
 | 
				
			||||||
    PLUSEQ,
 | 
					    PLUSEQ,
 | 
				
			||||||
    MINUSEQ,
 | 
					    MINUSEQ,
 | 
				
			||||||
 | 
					    PIPEEQ,
 | 
				
			||||||
 | 
					    AMPEQ,
 | 
				
			||||||
 | 
					    CARETEQ,
 | 
				
			||||||
 | 
					    SLASHEQ,
 | 
				
			||||||
 | 
					    STAREQ,
 | 
				
			||||||
    AMPAMP,
 | 
					    AMPAMP,
 | 
				
			||||||
    PIPEPIPE,
 | 
					    PIPEPIPE,
 | 
				
			||||||
    SHL,
 | 
					    SHL,
 | 
				
			||||||
@ -288,6 +293,11 @@ impl SyntaxKind {
 | 
				
			|||||||
            GTEQ => &SyntaxInfo { name: "GTEQ" },
 | 
					            GTEQ => &SyntaxInfo { name: "GTEQ" },
 | 
				
			||||||
            PLUSEQ => &SyntaxInfo { name: "PLUSEQ" },
 | 
					            PLUSEQ => &SyntaxInfo { name: "PLUSEQ" },
 | 
				
			||||||
            MINUSEQ => &SyntaxInfo { name: "MINUSEQ" },
 | 
					            MINUSEQ => &SyntaxInfo { name: "MINUSEQ" },
 | 
				
			||||||
 | 
					            PIPEEQ => &SyntaxInfo { name: "PIPEEQ" },
 | 
				
			||||||
 | 
					            AMPEQ => &SyntaxInfo { name: "AMPEQ" },
 | 
				
			||||||
 | 
					            CARETEQ => &SyntaxInfo { name: "CARETEQ" },
 | 
				
			||||||
 | 
					            SLASHEQ => &SyntaxInfo { name: "SLASHEQ" },
 | 
				
			||||||
 | 
					            STAREQ => &SyntaxInfo { name: "STAREQ" },
 | 
				
			||||||
            AMPAMP => &SyntaxInfo { name: "AMPAMP" },
 | 
					            AMPAMP => &SyntaxInfo { name: "AMPAMP" },
 | 
				
			||||||
            PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" },
 | 
					            PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" },
 | 
				
			||||||
            SHL => &SyntaxInfo { name: "SHL" },
 | 
					            SHL => &SyntaxInfo { name: "SHL" },
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user