2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
/// A single function parameter
|
2021-11-17 00:07:48 -08:00
|
|
|
#[derive(PartialEq, Debug, Clone, Serialize)]
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) struct Parameter<'src> {
|
|
|
|
/// An optional default expression
|
2020-06-13 01:49:13 -07:00
|
|
|
pub(crate) default: Option<Expression<'src>>,
|
2021-03-25 18:35:24 -07:00
|
|
|
/// Export parameter as environment variable
|
2021-09-16 06:44:40 -07:00
|
|
|
pub(crate) export: bool,
|
2021-11-17 00:07:48 -08:00
|
|
|
/// The kind of parameter
|
|
|
|
pub(crate) kind: ParameterKind,
|
|
|
|
/// The parameter name
|
|
|
|
pub(crate) name: Name<'src>,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
|
2021-07-28 18:06:57 -07:00
|
|
|
impl<'src> ColorDisplay for Parameter<'src> {
|
|
|
|
fn fmt(&self, f: &mut Formatter, color: Color) -> Result<(), fmt::Error> {
|
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
|
|
|
}
|
2022-12-15 13:08:53 -08:00
|
|
|
if self.export {
|
|
|
|
write!(f, "$")?;
|
|
|
|
}
|
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(())
|
|
|
|
}
|
|
|
|
}
|