diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-28 18:32:58 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-28 18:32:58 +0100 |
| commit | 406de22ee5cd74dc6f67743bad4710415bb50c41 (patch) | |
| tree | 37536600378cd325956201ea175469bc22db2b1a /src/syntax | |
| parent | 2d56e3c5e245bf8824bf0ea8f1f1a05cb9716dc5 (diff) | |
Remove method call syntax kind
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/ast.rs | 31 | ||||
| -rw-r--r-- | src/syntax/kind.rs | 5 | ||||
| -rw-r--r-- | src/syntax/node.rs | 20 | ||||
| -rw-r--r-- | src/syntax/parser.rs | 22 |
4 files changed, 27 insertions, 51 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 5704f171..78d895ff 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -157,10 +157,8 @@ pub enum Expr { Binary(Binary), /// A field access: `properties.age`. FieldAccess(FieldAccess), - /// An invocation of a function: `f(x, y)`. + /// An invocation of a function or method: `f(x, y)`. FuncCall(FuncCall), - /// An invocation of a method: `array.push(v)`. - MethodCall(MethodCall), /// A closure: `(x, y) => z`. Closure(Closure), /// A let binding: `let x = 1`. @@ -239,7 +237,6 @@ impl AstNode for Expr { SyntaxKind::Binary => node.cast().map(Self::Binary), SyntaxKind::FieldAccess => node.cast().map(Self::FieldAccess), SyntaxKind::FuncCall => node.cast().map(Self::FuncCall), - SyntaxKind::MethodCall => node.cast().map(Self::MethodCall), SyntaxKind::Closure => node.cast().map(Self::Closure), SyntaxKind::LetBinding => node.cast().map(Self::Let), SyntaxKind::SetRule => node.cast().map(Self::Set), @@ -299,7 +296,6 @@ impl AstNode for Expr { Self::Binary(v) => v.as_untyped(), Self::FieldAccess(v) => v.as_untyped(), Self::FuncCall(v) => v.as_untyped(), - Self::MethodCall(v) => v.as_untyped(), Self::Closure(v) => v.as_untyped(), Self::Let(v) => v.as_untyped(), Self::Set(v) => v.as_untyped(), @@ -335,7 +331,6 @@ impl Expr { Self::Parenthesized(_) => true, Self::FieldAccess(_) => true, Self::FuncCall(_) => true, - Self::MethodCall(_) => true, Self::Let(_) => true, Self::Set(_) => true, Self::Show(_) => true, @@ -1403,7 +1398,7 @@ impl FieldAccess { } node! { - /// An invocation of a function: `f(x, y)`. + /// An invocation of a function or method: `f(x, y)`. FuncCall } @@ -1420,28 +1415,6 @@ impl FuncCall { } node! { - /// An invocation of a method: `array.push(v)`. - MethodCall -} - -impl MethodCall { - /// The expression to call the method on. - pub fn target(&self) -> Expr { - self.0.cast_first_match().unwrap_or_default() - } - - /// The name of the method. - pub fn method(&self) -> Ident { - self.0.cast_last_match().unwrap_or_default() - } - - /// The arguments to the method. - pub fn args(&self) -> Args { - self.0.cast_last_match().unwrap_or_default() - } -} - -node! { /// A function call's argument list: `(12pt, y)`. Args } diff --git a/src/syntax/kind.rs b/src/syntax/kind.rs index b2b65a62..cf973e6a 100644 --- a/src/syntax/kind.rs +++ b/src/syntax/kind.rs @@ -210,10 +210,8 @@ pub enum SyntaxKind { Binary, /// A field access: `properties.age`. FieldAccess, - /// An invocation of a function: `f(x, y)`. + /// An invocation of a function or method: `f(x, y)`. FuncCall, - /// An invocation of a method: `array.push(v)`. - MethodCall, /// A function call's argument list: `(12pt, y)`. Args, /// Spreaded arguments or an argument sink: `..x`. @@ -416,7 +414,6 @@ impl SyntaxKind { Self::Binary => "binary expression", Self::FieldAccess => "field access", Self::FuncCall => "function call", - Self::MethodCall => "method call", Self::Args => "call arguments", Self::Spread => "spread", Self::Closure => "closure", diff --git a/src/syntax/node.rs b/src/syntax/node.rs index ed000788..049275ed 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -681,11 +681,6 @@ impl<'a> LinkedNode<'a> { self.parent.as_deref() } - /// Get the kind of this node's parent. - pub fn parent_kind(&self) -> Option<SyntaxKind> { - Some(self.parent()?.node.kind()) - } - /// Get the first previous non-trivia sibling node. pub fn prev_sibling(&self) -> Option<Self> { let parent = self.parent()?; @@ -713,6 +708,21 @@ impl<'a> LinkedNode<'a> { Some(next) } } + + /// Get the kind of this node's parent. + pub fn parent_kind(&self) -> Option<SyntaxKind> { + Some(self.parent()?.node.kind()) + } + + /// Get the kind of this node's first previous non-trivia sibling. + pub fn prev_sibling_kind(&self) -> Option<SyntaxKind> { + Some(self.prev_sibling()?.node.kind()) + } + + /// Get the kind of this node's next non-trivia sibling. + pub fn next_sibling_kind(&self) -> Option<SyntaxKind> { + Some(self.next_sibling()?.node.kind()) + } } /// Access to leafs. diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 1b5c10a3..602d9f2c 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -374,12 +374,12 @@ fn math_op(kind: SyntaxKind) -> Option<(SyntaxKind, SyntaxKind, ast::Assoc, usiz } fn math_args(p: &mut Parser) { - p.assert(SyntaxKind::Text); - let m = p.marker(); - let mut arg = p.marker(); + p.convert(SyntaxKind::LeftParen); + let mut namable = true; let mut named = None; + let mut arg = p.marker(); while !p.eof() && !p.at(SyntaxKind::Dollar) { if namable @@ -418,11 +418,14 @@ fn math_args(p: &mut Parser) { maybe_wrap_in_math(p, arg, named); } - p.wrap(m, SyntaxKind::Args); - if !p.eat_if(SyntaxKind::Text) { + if p.at(SyntaxKind::Text) && p.current_text() == ")" { + p.convert(SyntaxKind::RightParen); + } else { p.expected("closing paren"); p.balanced = false; } + + p.wrap(m, SyntaxKind::Args); } fn maybe_wrap_in_math(p: &mut Parser, arg: Marker, named: Option<Marker>) { @@ -512,14 +515,7 @@ fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) { if p.eat_if(SyntaxKind::Dot) { p.expect(SyntaxKind::Ident); - if p.directly_at(SyntaxKind::LeftParen) - || p.directly_at(SyntaxKind::LeftBracket) - { - args(p); - p.wrap(m, SyntaxKind::MethodCall); - } else { - p.wrap(m, SyntaxKind::FieldAccess) - } + p.wrap(m, SyntaxKind::FieldAccess); continue; } |
