use crate::span::{HasSpan, Span}; use super::{Expr, Ident, Space}; #[derive(Debug, Clone)] pub enum Field { /// `a[b]` /// /// Structure: `expr s0 [ s1 index s2 ]` Access { expr: Box, s0: Space, s1: Space, index: Box, s2: Space, span: Span, }, /// `a[b] = c` /// /// Structure: `expr s0 [ s1 index s2 ] s3 = s4 value` Assign { expr: Box, s0: Space, s1: Space, index: Box, s2: Space, s3: Space, s4: Space, value: Box, span: Span, }, /// `a.foo` /// /// Structure: `expr s0 . s1 ident` AccessIdent { expr: Box, s0: Space, s1: Space, ident: Ident, span: Span, }, /// `a.foo = b` /// /// Structure: `expr s0 . s1 ident s2 = s3 value` AssignIdent { expr: Box, s0: Space, s1: Space, ident: Ident, s2: Space, s3: Space, value: Box, span: Span, }, } impl HasSpan for Field { fn span(&self) -> Span { match self { Self::Access { span, .. } => *span, Self::Assign { span, .. } => *span, Self::AccessIdent { span, .. } => *span, Self::AssignIdent { span, .. } => *span, } } } impl Field { pub fn expr(self) -> Expr { Expr::Field(self) } }