mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Move Stmt Grammar
This commit is contained in:
parent
c04c06c4bc
commit
4d38b0dce1
@ -473,6 +473,7 @@ pub struct LifetimeParam {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for LifetimeParam {}
|
||||
impl ast::TypeBoundsOwner for LifetimeParam {}
|
||||
impl LifetimeParam {
|
||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![lifetime])
|
||||
@ -503,6 +504,19 @@ impl ConstParam {
|
||||
pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WherePred {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::TypeBoundsOwner for WherePred {}
|
||||
impl WherePred {
|
||||
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
|
||||
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
|
||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![lifetime])
|
||||
}
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Literal {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
@ -520,6 +534,29 @@ impl TokenTree {
|
||||
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LetStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for LetStmt {}
|
||||
impl LetStmt {
|
||||
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
|
||||
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
|
||||
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExprStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for ExprStmt {}
|
||||
impl ExprStmt {
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParenType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
@ -1179,42 +1216,6 @@ impl MacroStmts {
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WherePred {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::TypeBoundsOwner for WherePred {}
|
||||
impl WherePred {
|
||||
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
|
||||
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
|
||||
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![lifetime])
|
||||
}
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExprStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for ExprStmt {}
|
||||
impl ExprStmt {
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LetStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for LetStmt {}
|
||||
impl LetStmt {
|
||||
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
|
||||
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
|
||||
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PathSegment {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
@ -1880,6 +1881,17 @@ impl AstNode for ConstParam {
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for WherePred {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
||||
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 Literal {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
@ -1902,6 +1914,28 @@ impl AstNode for TokenTree {
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for LetStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
|
||||
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 ExprStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
|
||||
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 ParenType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
@ -2672,39 +2706,6 @@ impl AstNode for MacroStmts {
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for WherePred {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
|
||||
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 ExprStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
|
||||
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 LetStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT }
|
||||
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 PathSegment {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
@ -3671,6 +3672,11 @@ impl std::fmt::Display for ConstParam {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for WherePred {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for Literal {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
@ -3681,6 +3687,16 @@ impl std::fmt::Display for TokenTree {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for LetStmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExprStmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ParenType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
@ -4031,21 +4047,6 @@ impl std::fmt::Display for MacroStmts {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for WherePred {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ExprStmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for LetStmt {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for PathSegment {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
@ -194,6 +194,17 @@ Visibility =
|
||||
Attr =
|
||||
'#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
|
||||
|
||||
Stmt =
|
||||
LetStmt
|
||||
| ExprStmt
|
||||
|
||||
LetStmt =
|
||||
Attr* 'let' Pat (':' Type)?
|
||||
'=' initializer:Expr ';'
|
||||
|
||||
ExprStmt =
|
||||
Attr* Expr ';'?
|
||||
|
||||
Type =
|
||||
ParenType
|
||||
| TupleType
|
||||
@ -456,13 +467,6 @@ MacroStmts =
|
||||
statements:Stmt*
|
||||
Expr?
|
||||
|
||||
ExprStmt =
|
||||
Attr* Expr ';'
|
||||
|
||||
LetStmt =
|
||||
Attr* 'let' Pat (':' Type)
|
||||
'=' initializer:Expr ';'
|
||||
|
||||
Path =
|
||||
(qualifier:Path '::')? segment:PathSegment
|
||||
|
||||
@ -490,10 +494,6 @@ LifetimeArg =
|
||||
ConstArg =
|
||||
Literal | BlockExpr BlockExpr
|
||||
|
||||
Stmt =
|
||||
LetStmt
|
||||
| ExprStmt
|
||||
|
||||
Pat =
|
||||
OrPat
|
||||
| ParenPat
|
||||
|
Loading…
Reference in New Issue
Block a user