sway_parse/
where_clause.rs

1use crate::{Parse, ParseResult, Parser};
2
3use sway_ast::punctuated::Punctuated;
4use sway_ast::{WhereBound, WhereClause};
5
6impl Parse for WhereClause {
7    fn parse(parser: &mut Parser) -> ParseResult<WhereClause> {
8        let where_token = parser.parse()?;
9        let mut value_separator_pairs = Vec::new();
10        let final_value_opt = loop {
11            let ty_name = match parser.take() {
12                Some(ty_name) => ty_name,
13                None => break None,
14            };
15            let colon_token = parser.parse()?;
16            let bounds = parser.parse()?;
17            let where_bound = WhereBound {
18                ty_name,
19                colon_token,
20                bounds,
21            };
22            match parser.take() {
23                Some(comma_token) => value_separator_pairs.push((where_bound, comma_token)),
24                None => break Some(Box::new(where_bound)),
25            }
26        };
27        let bounds = Punctuated {
28            value_separator_pairs,
29            final_value_opt,
30        };
31        Ok(WhereClause {
32            where_token,
33            bounds,
34        })
35    }
36}