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

Method misparsed_ctor

codegraph-kernel/src/dart.rs:1804–1849  ·  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

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