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

Function additive_expression

graphlite/src/ast/parser.rs:1858–1890  ·  view source on GitHub ↗

Parse additive expressions: mult_expr (+|-|*|||) mult_expr

(tokens: &[Token])

Source from the content-addressed store, hash-verified

1856
1857/// Parse additive expressions: mult_expr (+|-|*|||) mult_expr
1858fn additive_expression(tokens: &[Token]) -> IResult<&[Token], Expression> {
1859 map(
1860 tuple((
1861 multiplicative_expression,
1862 many0(tuple((
1863 alt((
1864 expect_token(Token::Plus),
1865 expect_token(Token::Minus),
1866 expect_token(Token::Dash), // Accept Dash as arithmetic minus
1867 expect_token(Token::Concat), // Concatenation operator
1868 )),
1869 multiplicative_expression,
1870 ))),
1871 )),
1872 |(first, rest)| {
1873 rest.into_iter().fold(first, |left, (op, right)| {
1874 let operator = match op {
1875 Token::Plus => Operator::Plus,
1876 Token::Minus => Operator::Minus,
1877 Token::Dash => Operator::Minus, // Treat Dash as arithmetic minus
1878 Token::Concat => Operator::Concat, // Concatenation
1879 _ => Operator::Plus, // Should not happen
1880 };
1881 Expression::Binary(BinaryExpression {
1882 left: Box::new(left),
1883 operator,
1884 right: Box::new(right),
1885 location: Location::default(),
1886 })
1887 })
1888 },
1889 )(tokens)
1890}
1891
1892/// Parse multiplicative expressions: postfix (*|/) postfix
1893fn multiplicative_expression(tokens: &[Token]) -> IResult<&[Token], Expression> {

Callers

nothing calls this directly

Calls 1

expect_tokenFunction · 0.85

Tested by

no test coverage detected