diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-19 16:37:16 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-19 16:37:16 +0200 |
| commit | 7a2cc3e7d29d16c5cf9b5a93a688e14da93c8662 (patch) | |
| tree | 8ca787c56b84b83f5d34ee7b4701c0e8f4778753 /src/parse/mod.rs | |
| parent | 255d4c620f39133b40a9132843781f2a620a6008 (diff) | |
Field access
Diffstat (limited to 'src/parse/mod.rs')
| -rw-r--r-- | src/parse/mod.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index be947170..c387de0c 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -368,10 +368,9 @@ fn expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) -> ParseResult { }; loop { - // Exclamation mark, parenthesis or bracket means this is a function - // call. + // Parenthesis or bracket means this is a function call. if let Some(NodeKind::LeftParen | NodeKind::LeftBracket) = p.peek_direct() { - func_call(p, marker)?; + marker.perform(p, NodeKind::FuncCall, |p| args(p, true, true))?; continue; } @@ -379,8 +378,14 @@ fn expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) -> ParseResult { break; } - if p.at(&NodeKind::Dot) { - method_call(p, marker)?; + // Method call or field access. + if p.eat_if(&NodeKind::Dot) { + ident(p)?; + if let Some(NodeKind::LeftParen | NodeKind::LeftBracket) = p.peek_direct() { + marker.perform(p, NodeKind::MethodCall, |p| args(p, true, true))?; + } else { + marker.end(p, NodeKind::FieldAccess); + } continue; } @@ -715,20 +720,6 @@ fn content_block(p: &mut Parser) { }); } -/// Parse a function call. -fn func_call(p: &mut Parser, callee: Marker) -> ParseResult { - callee.perform(p, NodeKind::FuncCall, |p| args(p, true, true)) -} - -/// Parse a method call. -fn method_call(p: &mut Parser, marker: Marker) -> ParseResult { - marker.perform(p, NodeKind::MethodCall, |p| { - p.eat_assert(&NodeKind::Dot); - ident(p)?; - args(p, true, true) - }) -} - /// Parse the arguments to a function call. fn args(p: &mut Parser, direct: bool, brackets: bool) -> ParseResult { match if direct { p.peek_direct() } else { p.peek() } { |
