sway_parse/item/
item_const.rsuse crate::{Parse, ParseResult, Parser};
use sway_ast::ItemConst;
impl Parse for ItemConst {
fn parse(parser: &mut Parser) -> ParseResult<ItemConst> {
let visibility = parser.take();
let const_token = parser.parse()?;
let name = parser.parse()?;
let ty_opt = match parser.take() {
Some(colon_token) => {
let ty = parser.parse()?;
Some((colon_token, ty))
}
None => None,
};
let eq_token_opt = parser.take();
let expr_opt = match &eq_token_opt {
Some(_eq) => Some(parser.parse()?),
None => None,
};
let semicolon_token = parser.peek().unwrap_or_default();
Ok(ItemConst {
visibility,
const_token,
name,
ty_opt,
eq_token_opt,
expr_opt,
semicolon_token,
})
}
}