mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	handle multibyte tokens
This commit is contained in:
		
							parent
							
								
									f3489e8111
								
							
						
					
					
						commit
						0d9210e9bc
					
				@ -221,17 +221,21 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
 | 
				
			|||||||
        if child == first_child || child == last_child || child.kind().is_trivia() {
 | 
					        if child == first_child || child == last_child || child.kind().is_trivia() {
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if child.kind().is_punct() {
 | 
				
			||||||
 | 
					            let leaves = child
 | 
				
			||||||
 | 
					                .leaf_text()
 | 
				
			||||||
 | 
					                .unwrap()
 | 
				
			||||||
 | 
					                .chars()
 | 
				
			||||||
 | 
					                .map(|char| tt::Punct { char })
 | 
				
			||||||
 | 
					                .map(tt::Leaf::from)
 | 
				
			||||||
 | 
					                .map(tt::TokenTree::from);
 | 
				
			||||||
 | 
					            token_trees.extend(leaves);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
            let child: tt::TokenTree = if child.kind() == TOKEN_TREE {
 | 
					            let child: tt::TokenTree = if child.kind() == TOKEN_TREE {
 | 
				
			||||||
                convert_tt(child)?.into()
 | 
					                convert_tt(child)?.into()
 | 
				
			||||||
            } else if child.kind().is_keyword() || child.kind() == IDENT {
 | 
					            } else if child.kind().is_keyword() || child.kind() == IDENT {
 | 
				
			||||||
                let text = child.leaf_text().unwrap().clone();
 | 
					                let text = child.leaf_text().unwrap().clone();
 | 
				
			||||||
                tt::Leaf::from(tt::Ident { text }).into()
 | 
					                tt::Leaf::from(tt::Ident { text }).into()
 | 
				
			||||||
        } else if child.kind().is_punct() {
 | 
					 | 
				
			||||||
            // FIXME: multibyte tokens
 | 
					 | 
				
			||||||
            tt::Leaf::from(tt::Punct {
 | 
					 | 
				
			||||||
                char: child.text().char_at(0)?,
 | 
					 | 
				
			||||||
            })
 | 
					 | 
				
			||||||
            .into()
 | 
					 | 
				
			||||||
            } else if child.kind().is_literal() {
 | 
					            } else if child.kind().is_literal() {
 | 
				
			||||||
                tt::Leaf::from(tt::Literal {
 | 
					                tt::Leaf::from(tt::Literal {
 | 
				
			||||||
                    text: child.leaf_text().unwrap().clone(),
 | 
					                    text: child.leaf_text().unwrap().clone(),
 | 
				
			||||||
@ -243,6 +247,7 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
            token_trees.push(child)
 | 
					            token_trees.push(child)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let res = tt::Subtree {
 | 
					    let res = tt::Subtree {
 | 
				
			||||||
        delimiter,
 | 
					        delimiter,
 | 
				
			||||||
 | 
				
			|||||||
@ -86,14 +86,17 @@ pub(crate) fn parse(tt: &tt::Subtree) -> Option<MacroRules> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
 | 
					fn parse_rule(p: &mut RulesParser) -> Option<Rule> {
 | 
				
			||||||
    let lhs = parse_subtree(p.eat_subtree()?)?;
 | 
					    let lhs = parse_subtree(p.eat_subtree()?)?;
 | 
				
			||||||
    p.eat_punct('=');
 | 
					    p.eat_punct('=')?;
 | 
				
			||||||
    p.eat_punct('>');
 | 
					    p.eat_punct('>')?;
 | 
				
			||||||
    let rhs = parse_subtree(p.eat_subtree()?)?;
 | 
					    let rhs = parse_subtree(p.eat_subtree()?)?;
 | 
				
			||||||
    Some(Rule { lhs, rhs })
 | 
					    Some(Rule { lhs, rhs })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
 | 
					fn parse_subtree(tt: &tt::Subtree) -> Option<Subtree> {
 | 
				
			||||||
    None
 | 
					    Some(Subtree {
 | 
				
			||||||
 | 
					        token_trees: Vec::new(),
 | 
				
			||||||
 | 
					        delimiter: Delimiter::None,
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct RulesParser<'a> {
 | 
					struct RulesParser<'a> {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user