mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Parse builtin# syntax
This commit is contained in:
parent
db4684ef6c
commit
9b8eb807a3
17 changed files with 264 additions and 88 deletions
|
@ -804,6 +804,19 @@ impl ArrayExpr {
|
|||
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AsmExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for AsmExpr {}
|
||||
impl AsmExpr {
|
||||
pub fn builtin_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![builtin]) }
|
||||
pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
|
||||
pub fn asm_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![asm]) }
|
||||
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
|
||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AwaitExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -822,16 +835,6 @@ pub struct BinExpr {
|
|||
impl ast::HasAttrs for BinExpr {}
|
||||
impl BinExpr {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BoxExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for BoxExpr {}
|
||||
impl BoxExpr {
|
||||
pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BreakExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -915,6 +918,21 @@ impl ForExpr {
|
|||
pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FormatArgsExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for FormatArgsExpr {}
|
||||
impl FormatArgsExpr {
|
||||
pub fn builtin_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![builtin]) }
|
||||
pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
|
||||
pub fn format_args_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![format_args])
|
||||
}
|
||||
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
|
||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct IfExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -984,6 +1002,21 @@ impl MethodCallExpr {
|
|||
pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct OffsetOfExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::HasAttrs for OffsetOfExpr {}
|
||||
impl OffsetOfExpr {
|
||||
pub fn builtin_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![builtin]) }
|
||||
pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
|
||||
pub fn offset_of_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![offset_of])
|
||||
}
|
||||
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
|
||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParenExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -1555,10 +1588,10 @@ pub enum Type {
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Expr {
|
||||
ArrayExpr(ArrayExpr),
|
||||
AsmExpr(AsmExpr),
|
||||
AwaitExpr(AwaitExpr),
|
||||
BinExpr(BinExpr),
|
||||
BlockExpr(BlockExpr),
|
||||
BoxExpr(BoxExpr),
|
||||
BreakExpr(BreakExpr),
|
||||
CallExpr(CallExpr),
|
||||
CastExpr(CastExpr),
|
||||
|
@ -1566,6 +1599,7 @@ pub enum Expr {
|
|||
ContinueExpr(ContinueExpr),
|
||||
FieldExpr(FieldExpr),
|
||||
ForExpr(ForExpr),
|
||||
FormatArgsExpr(FormatArgsExpr),
|
||||
IfExpr(IfExpr),
|
||||
IndexExpr(IndexExpr),
|
||||
Literal(Literal),
|
||||
|
@ -1573,6 +1607,7 @@ pub enum Expr {
|
|||
MacroExpr(MacroExpr),
|
||||
MatchExpr(MatchExpr),
|
||||
MethodCallExpr(MethodCallExpr),
|
||||
OffsetOfExpr(OffsetOfExpr),
|
||||
ParenExpr(ParenExpr),
|
||||
PathExpr(PathExpr),
|
||||
PrefixExpr(PrefixExpr),
|
||||
|
@ -2453,6 +2488,17 @@ impl AstNode for ArrayExpr {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for AsmExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == ASM_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for AwaitExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -2475,17 +2521,6 @@ impl AstNode for BinExpr {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for BoxExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == BOX_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for BreakExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == BREAK_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -2563,6 +2598,17 @@ impl AstNode for ForExpr {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for FormatArgsExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == FORMAT_ARGS_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for IfExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == IF_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -2640,6 +2686,17 @@ impl AstNode for MethodCallExpr {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for OffsetOfExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == OFFSET_OF_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ParenExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -3373,6 +3430,9 @@ impl AstNode for Type {
|
|||
impl From<ArrayExpr> for Expr {
|
||||
fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) }
|
||||
}
|
||||
impl From<AsmExpr> for Expr {
|
||||
fn from(node: AsmExpr) -> Expr { Expr::AsmExpr(node) }
|
||||
}
|
||||
impl From<AwaitExpr> for Expr {
|
||||
fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) }
|
||||
}
|
||||
|
@ -3382,9 +3442,6 @@ impl From<BinExpr> for Expr {
|
|||
impl From<BlockExpr> for Expr {
|
||||
fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) }
|
||||
}
|
||||
impl From<BoxExpr> for Expr {
|
||||
fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) }
|
||||
}
|
||||
impl From<BreakExpr> for Expr {
|
||||
fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) }
|
||||
}
|
||||
|
@ -3406,6 +3463,9 @@ impl From<FieldExpr> for Expr {
|
|||
impl From<ForExpr> for Expr {
|
||||
fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) }
|
||||
}
|
||||
impl From<FormatArgsExpr> for Expr {
|
||||
fn from(node: FormatArgsExpr) -> Expr { Expr::FormatArgsExpr(node) }
|
||||
}
|
||||
impl From<IfExpr> for Expr {
|
||||
fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) }
|
||||
}
|
||||
|
@ -3427,6 +3487,9 @@ impl From<MatchExpr> for Expr {
|
|||
impl From<MethodCallExpr> for Expr {
|
||||
fn from(node: MethodCallExpr) -> Expr { Expr::MethodCallExpr(node) }
|
||||
}
|
||||
impl From<OffsetOfExpr> for Expr {
|
||||
fn from(node: OffsetOfExpr) -> Expr { Expr::OffsetOfExpr(node) }
|
||||
}
|
||||
impl From<ParenExpr> for Expr {
|
||||
fn from(node: ParenExpr) -> Expr { Expr::ParenExpr(node) }
|
||||
}
|
||||
|
@ -3474,10 +3537,10 @@ impl AstNode for Expr {
|
|||
matches!(
|
||||
kind,
|
||||
ARRAY_EXPR
|
||||
| ASM_EXPR
|
||||
| AWAIT_EXPR
|
||||
| BIN_EXPR
|
||||
| BLOCK_EXPR
|
||||
| BOX_EXPR
|
||||
| BREAK_EXPR
|
||||
| CALL_EXPR
|
||||
| CAST_EXPR
|
||||
|
@ -3485,6 +3548,7 @@ impl AstNode for Expr {
|
|||
| CONTINUE_EXPR
|
||||
| FIELD_EXPR
|
||||
| FOR_EXPR
|
||||
| FORMAT_ARGS_EXPR
|
||||
| IF_EXPR
|
||||
| INDEX_EXPR
|
||||
| LITERAL
|
||||
|
@ -3492,6 +3556,7 @@ impl AstNode for Expr {
|
|||
| MACRO_EXPR
|
||||
| MATCH_EXPR
|
||||
| METHOD_CALL_EXPR
|
||||
| OFFSET_OF_EXPR
|
||||
| PAREN_EXPR
|
||||
| PATH_EXPR
|
||||
| PREFIX_EXPR
|
||||
|
@ -3511,10 +3576,10 @@ impl AstNode for Expr {
|
|||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
ARRAY_EXPR => Expr::ArrayExpr(ArrayExpr { syntax }),
|
||||
ASM_EXPR => Expr::AsmExpr(AsmExpr { syntax }),
|
||||
AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
|
||||
BIN_EXPR => Expr::BinExpr(BinExpr { syntax }),
|
||||
BLOCK_EXPR => Expr::BlockExpr(BlockExpr { syntax }),
|
||||
BOX_EXPR => Expr::BoxExpr(BoxExpr { syntax }),
|
||||
BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
|
||||
CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
|
||||
CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
|
||||
|
@ -3522,6 +3587,7 @@ impl AstNode for Expr {
|
|||
CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
|
||||
FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
|
||||
FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
|
||||
FORMAT_ARGS_EXPR => Expr::FormatArgsExpr(FormatArgsExpr { syntax }),
|
||||
IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
|
||||
INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
|
||||
LITERAL => Expr::Literal(Literal { syntax }),
|
||||
|
@ -3529,6 +3595,7 @@ impl AstNode for Expr {
|
|||
MACRO_EXPR => Expr::MacroExpr(MacroExpr { syntax }),
|
||||
MATCH_EXPR => Expr::MatchExpr(MatchExpr { syntax }),
|
||||
METHOD_CALL_EXPR => Expr::MethodCallExpr(MethodCallExpr { syntax }),
|
||||
OFFSET_OF_EXPR => Expr::OffsetOfExpr(OffsetOfExpr { syntax }),
|
||||
PAREN_EXPR => Expr::ParenExpr(ParenExpr { syntax }),
|
||||
PATH_EXPR => Expr::PathExpr(PathExpr { syntax }),
|
||||
PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
|
||||
|
@ -3550,10 +3617,10 @@ impl AstNode for Expr {
|
|||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
Expr::ArrayExpr(it) => &it.syntax,
|
||||
Expr::AsmExpr(it) => &it.syntax,
|
||||
Expr::AwaitExpr(it) => &it.syntax,
|
||||
Expr::BinExpr(it) => &it.syntax,
|
||||
Expr::BlockExpr(it) => &it.syntax,
|
||||
Expr::BoxExpr(it) => &it.syntax,
|
||||
Expr::BreakExpr(it) => &it.syntax,
|
||||
Expr::CallExpr(it) => &it.syntax,
|
||||
Expr::CastExpr(it) => &it.syntax,
|
||||
|
@ -3561,6 +3628,7 @@ impl AstNode for Expr {
|
|||
Expr::ContinueExpr(it) => &it.syntax,
|
||||
Expr::FieldExpr(it) => &it.syntax,
|
||||
Expr::ForExpr(it) => &it.syntax,
|
||||
Expr::FormatArgsExpr(it) => &it.syntax,
|
||||
Expr::IfExpr(it) => &it.syntax,
|
||||
Expr::IndexExpr(it) => &it.syntax,
|
||||
Expr::Literal(it) => &it.syntax,
|
||||
|
@ -3568,6 +3636,7 @@ impl AstNode for Expr {
|
|||
Expr::MacroExpr(it) => &it.syntax,
|
||||
Expr::MatchExpr(it) => &it.syntax,
|
||||
Expr::MethodCallExpr(it) => &it.syntax,
|
||||
Expr::OffsetOfExpr(it) => &it.syntax,
|
||||
Expr::ParenExpr(it) => &it.syntax,
|
||||
Expr::PathExpr(it) => &it.syntax,
|
||||
Expr::PrefixExpr(it) => &it.syntax,
|
||||
|
@ -4028,9 +4097,9 @@ impl AstNode for AnyHasAttrs {
|
|||
| TYPE_PARAM
|
||||
| LET_STMT
|
||||
| ARRAY_EXPR
|
||||
| ASM_EXPR
|
||||
| AWAIT_EXPR
|
||||
| BIN_EXPR
|
||||
| BOX_EXPR
|
||||
| BREAK_EXPR
|
||||
| CALL_EXPR
|
||||
| CAST_EXPR
|
||||
|
@ -4038,12 +4107,14 @@ impl AstNode for AnyHasAttrs {
|
|||
| CONTINUE_EXPR
|
||||
| FIELD_EXPR
|
||||
| FOR_EXPR
|
||||
| FORMAT_ARGS_EXPR
|
||||
| IF_EXPR
|
||||
| INDEX_EXPR
|
||||
| LITERAL
|
||||
| LOOP_EXPR
|
||||
| MATCH_EXPR
|
||||
| METHOD_CALL_EXPR
|
||||
| OFFSET_OF_EXPR
|
||||
| PAREN_EXPR
|
||||
| PATH_EXPR
|
||||
| PREFIX_EXPR
|
||||
|
@ -4620,6 +4691,11 @@ impl std::fmt::Display for ArrayExpr {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AsmExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AwaitExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -4630,11 +4706,6 @@ impl std::fmt::Display for BinExpr {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for BoxExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for BreakExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -4670,6 +4741,11 @@ impl std::fmt::Display for ForExpr {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for FormatArgsExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for IfExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -4705,6 +4781,11 @@ impl std::fmt::Display for MethodCallExpr {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for OffsetOfExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ParenExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue