MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / vector_literal

Function vector_literal

graphlite/src/ast/lexer.rs:1805–1842  ·  view source on GitHub ↗

Parse vector literals

(input: &str)

Source from the content-addressed store, hash-verified

1803
1804/// Parse vector literals
1805fn vector_literal(input: &str) -> IResult<&str, Vec<f64>> {
1806 map(
1807 recognize(tuple((
1808 char('['),
1809 // Only match if there's at least one comma (indicating multiple elements)
1810 // or multiple digits/floats, to avoid consuming single element array indexing
1811 alt((
1812 // Multiple elements with comma
1813 tuple((
1814 take_while1(|c: char| c.is_ascii_digit() || c == '.' || c == ' ' || c == '-'),
1815 char(','),
1816 take_while(|c: char| {
1817 c.is_ascii_digit() || c == '.' || c == ',' || c == ' ' || c == '-'
1818 }),
1819 )),
1820 // Or empty vector []
1821 tuple((
1822 take_while(|c: char| c == ' '),
1823 peek(char(']')),
1824 take_while(|c: char| c == ' '),
1825 )),
1826 )),
1827 char(']'),
1828 ))),
1829 |s: &str| {
1830 // Parse the vector content
1831 let content = &s[1..s.len() - 1]; // Remove [ and ]
1832 if content.trim().is_empty() {
1833 vec![]
1834 } else {
1835 content
1836 .split(',')
1837 .map(|x| x.trim().parse::<f64>().unwrap_or(0.0))
1838 .collect()
1839 }
1840 },
1841 )(input)
1842}
1843
1844/// Parse variables (starting with $)
1845fn variable(input: &str) -> IResult<&str, &str> {

Callers

nothing calls this directly

Calls 2

lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected