2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
/// A single function parameter
|
2017-11-16 23:30:08 -08:00
|
|
|
#[derive(PartialEq, Debug)]
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) struct Parameter<'src> {
|
|
|
|
/// The parameter name
|
2020-06-13 01:49:13 -07:00
|
|
|
pub(crate) name: Name<'src>,
|
|
|
|
/// The kind of parameter
|
|
|
|
pub(crate) kind: ParameterKind,
|
2019-11-07 10:55:15 -08:00
|
|
|
/// An optional default expression
|
2020-06-13 01:49:13 -07:00
|
|
|
pub(crate) default: Option<Expression<'src>>,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
impl<'src> Display for Parameter<'src> {
|
2019-04-11 15:23:14 -07:00
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
2017-11-16 23:30:08 -08:00
|
|
|
let color = Color::fmt(f);
|
2020-06-13 01:49:13 -07:00
|
|
|
if let Some(prefix) = self.kind.prefix() {
|
|
|
|
write!(f, "{}", color.annotation().paint(prefix))?;
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
2019-11-07 10:55:15 -08:00
|
|
|
write!(f, "{}", color.parameter().paint(self.name.lexeme()))?;
|
2017-11-16 23:30:08 -08:00
|
|
|
if let Some(ref default) = self.default {
|
2019-04-11 23:58:08 -07:00
|
|
|
write!(f, "={}", color.string().paint(&default.to_string()))?;
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|