MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / misparsed_ctor

Method misparsed_ctor

codegraph-kernel/src/dart.rs:1797–1842  ·  view source on GitHub ↗

dartMisparsedCtor (dart.ts) — a generic constructor call tree-sitter-dart parsed as comparisons and a dot shorthand, found from the relational expression `tail` that holds its `>`: `(Future < void) > .delayed(d)`, or, with two type arguments in a list, `Map < String` then `int > .of(m)` in the next item. Recovered when laid out as a call: `<` against the type, a type in each argument, `>` against

(&self, tail: Node<'t>)

Source from the content-addressed store, hash-verified

1795 /// then `int > .of(m)` in the next item. Recovered when laid out as a call:
1796 /// `<` against the type, a type in each argument, `>` against the `.name`.
1797 fn misparsed_ctor(&self, tail: Node<'t>) -> Option<MisparsedCtor<'t>> {
1798 if tail.kind() != "relational_expression" {
1799 return None;
1800 }
1801 let mut cursor = tail.walk();
1802 let kids: Vec<Node<'t>> = tail.named_children(&mut cursor).collect();
1803 let dot_at = kids.iter().position(|c| c.kind() == "dot_shorthand")?;
1804 if dot_at < 2 {
1805 return None;
1806 }
1807 let dot = kids[dot_at];
1808 let gt = kids[dot_at - 1];
1809 if gt.kind() != "relational_operator" || gt.child(0)?.kind() != ">" || gt.end_byte() != dot.start_byte() {
1810 return None;
1811 }
1812 let call = kids.get(dot_at + 1)?;
1813 let mut cc = call.walk();
1814 if call.kind() != "selector" || !call.named_children(&mut cc).any(|c| c.kind() == "argument_part") {
1815 return None;
1816 }
1817 let name = dot.named_child(0).filter(|n| n.kind() == "identifier" && dot.named_child_count() == 1)?;
1818 let first = kids[0];
1819 // One type argument: `(X < T) > .name(…)`.
1820 if dot_at == 2 && first.kind() == "relational_expression" {
1821 let lt = self.ctor_type_args_start(first)?;
1822 let (head, type_name) = self.ctor_callee(first, lt)?;
1823 let (arg, next) = self.type_arg_part(lt.next_named_sibling())?;
1824 if next.is_some() {
1825 return None;
1826 }
1827 return Some(MisparsedCtor { head, type_name, name, type_args: [Some(arg), None], gt, start: first });
1828 }
1829 // Two, split at their comma: `X < A`, then `B > .name(…)` in the next item.
1830 let (last, last_next) = self.type_arg_part(Some(first))?;
1831 if last_next != Some(gt) {
1832 return None;
1833 }
1834 let start = self.prev_listed_expression(tail)?;
1835 let lt = self.ctor_type_args_start(start)?;
1836 let (head, type_name) = self.ctor_callee(start, lt)?;
1837 let (arg, next) = self.type_arg_part(lt.next_named_sibling())?;
1838 if next.is_some() {
1839 return None;
1840 }
1841 Some(MisparsedCtor { head, type_name, name, type_args: [Some(arg), Some(last)], gt, start })
1842 }
1843
1844 /// dartMisparsedCtorIn (dart.ts) — whether the relational expression `rel`
1845 /// holds part of a misparsed generic constructor call before its `>`,

Callers 3

misparsed_ctor_inMethod · 0.80
next_listed_ctorMethod · 0.80
visit_bodyMethod · 0.80

Calls 8

positionMethod · 0.80
ctor_type_args_startMethod · 0.80
ctor_calleeMethod · 0.80
type_arg_partMethod · 0.80
getMethod · 0.65
walkMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected