mirror of
https://github.com/rm-dr/daisy
synced 2025-07-01 06:33:34 -07:00
Added variable and constant listing
This commit is contained in:
@ -91,6 +91,96 @@ pub fn write(target: &Path) {
|
||||
writeln!(file, "\t\t\t_ => None\n\t\t}}\n\t}}\n").unwrap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writeln!(file,
|
||||
concat!(
|
||||
"\tpub fn all_consts() -> &'static [Constant] {{\n",
|
||||
"\t\treturn &["
|
||||
)
|
||||
).unwrap();
|
||||
|
||||
for c in constants {
|
||||
writeln!(file,
|
||||
"\t\t\tConstant::{e},",
|
||||
e = c["enum_name"].as_str().unwrap(),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
writeln!(file, "\t\t]\n\t}}\n").unwrap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writeln!(file,
|
||||
concat!(
|
||||
"\tpub fn source_strings(&self) -> &'static [&'static str] {{\n",
|
||||
"\t\tmatch self {{"
|
||||
)
|
||||
).unwrap();
|
||||
|
||||
for c in constants {
|
||||
write!(file,
|
||||
"\t\t\tConstant::{e} => &[",
|
||||
e = c["enum_name"].as_str().unwrap(),
|
||||
).unwrap();
|
||||
|
||||
if c["strings"].is_array() {
|
||||
for s in c["strings"].as_array().unwrap() {
|
||||
write!(file,
|
||||
"\"{s}\",",
|
||||
s = s.as_str().unwrap()
|
||||
).unwrap();
|
||||
}
|
||||
write!(file,
|
||||
"],",
|
||||
).unwrap();
|
||||
} else {
|
||||
write!(file,
|
||||
"\"{s}\"],",
|
||||
s = c["strings"].as_str().unwrap()
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
write!(file,
|
||||
"\n",
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
writeln!(file, "\t\t}}\n\t}}\n").unwrap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writeln!(file,
|
||||
concat!(
|
||||
"\tpub fn pretty_name(&self) -> Option<&'static str> {{\n",
|
||||
"\t\tmatch self {{"
|
||||
)
|
||||
).unwrap();
|
||||
|
||||
for c in constants {
|
||||
if c.as_table().unwrap().contains_key("pretty_name") {
|
||||
writeln!(file,
|
||||
"\t\t\tConstant::{e} => Some(&\"{s}\"),",
|
||||
e = c["enum_name"].as_str().unwrap(),
|
||||
s = c["pretty_name"].as_str().unwrap()
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(file, "\t\t\t_ => None\n\t\t}}\n\t}}\n").unwrap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writeln!(file,
|
||||
concat!(
|
||||
"\tpub fn value(&self) -> Expression {{\n",
|
||||
|
@ -6,90 +6,108 @@
|
||||
# strings: string or string array. What strings will be parsed as this constant.
|
||||
# The first entry in this array tells daisy how to print this constant.
|
||||
# value: value of this constant. Will be evaluated just like user input.
|
||||
# unit: true if this constant represents a "fake unit"
|
||||
# pretty_name: string, name of this constant in help texts.
|
||||
# if this is missing, this constant will not be listed.
|
||||
|
||||
[[constant]]
|
||||
enum_name = "Pi"
|
||||
pretty_name = "π"
|
||||
strings = ["π", "pi"]
|
||||
value = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "Phi"
|
||||
strings = ["φ", "phi", "goldenratio"]
|
||||
pretty_name = "Golden ratio"
|
||||
strings = ["φ", "phi"]
|
||||
value = "1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "Euler"
|
||||
pretty_name = "Euler's number"
|
||||
strings = "e"
|
||||
value = "2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "LightSpeed"
|
||||
pretty_name = "Speed of light"
|
||||
strings = "c"
|
||||
value = "299792458 meter/second"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "ElectricConstant"
|
||||
pretty_name = "Electric constant"
|
||||
strings = ["ε₀", "epsilon_zero", "eps_zero", "electricconstant"]
|
||||
value = "8.8541878128e-12 F/m"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "ElectronCharge"
|
||||
pretty_name = "Electron charge"
|
||||
strings = ["electroncharge", "elementarycharge"]
|
||||
value = "1.602176634e-19 C"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "ElectronMass"
|
||||
pretty_name = "Electron mass"
|
||||
strings = ["me", "m_e", "electronmass"]
|
||||
value = "9.1093837015-31 kg"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "ProtonMass"
|
||||
pretty_name = "Proton mass"
|
||||
strings = ["mp", "m_p", "protonmass"]
|
||||
value = "1.67262192369e-27 kg"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "GravityConstant"
|
||||
pretty_name = "Graviational constant"
|
||||
strings = "G"
|
||||
value = "6.67430e-11 (m^3)/(s^2 * kg)"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "GravityEarth"
|
||||
pretty_name = "Standard Earth gravity"
|
||||
strings = ["g₀", "g_zero", "gravity"]
|
||||
value = "9.80665 m/(s^2)"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "BoltzmannConstant"
|
||||
pretty_name = "Boltzmann constant"
|
||||
strings = ["k_B", "boltzmannconstant"]
|
||||
value = "1.380649e-23 J/K"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "FaradayConstant"
|
||||
pretty_name = "Faraday constant"
|
||||
strings = ["faradayconstant"]
|
||||
value = "9.64853321233100184e4 C/mol"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "MagneticConstant"
|
||||
pretty_name = "Magnetic constant"
|
||||
strings = ["μ₀","mu_zero"]
|
||||
value = "1.25663706212 N/(A*A)"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "AvogadroConstant"
|
||||
pretty_name = "Avogadro constant"
|
||||
strings = ["N_A", "avogadroconstant"]
|
||||
value = "6.02214076e23 mol^-1"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PlanckConstant"
|
||||
pretty_name = "Planck constant"
|
||||
strings = ["planckconstant"]
|
||||
value = "6.62607015e-34 J/Hz"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "Hbar"
|
||||
pretty_name = "Reduced Planck constant"
|
||||
strings = ["ℏ", "h_bar"]
|
||||
value = "planckconstant / (2 pi)"
|
||||
|
||||
[[constant]]
|
||||
enum_name = "GasConstant"
|
||||
pretty_name = "Gas constant"
|
||||
strings = ["R", "gasconstant"]
|
||||
value = "avogadroconstant * boltzmannconstant"
|
||||
|
||||
@ -112,95 +130,79 @@ value = "avogadroconstant * boltzmannconstant"
|
||||
enum_name = "MPG"
|
||||
strings = "mpg"
|
||||
value = "mile/gallon"
|
||||
unit = true
|
||||
|
||||
|
||||
[[constant]]
|
||||
enum_name = "MPH"
|
||||
strings = "mph"
|
||||
value = "mile/hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "DPI"
|
||||
strings = "dpi"
|
||||
value = "dot/inch"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PPI"
|
||||
strings = "ppi"
|
||||
value = "pixel/inch"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "FPS"
|
||||
strings = "fps"
|
||||
value = "frame/second"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PCT"
|
||||
strings = "pct"
|
||||
value = "0.01"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PPM"
|
||||
strings = "ppm"
|
||||
value = "1e-6"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PPB"
|
||||
strings = "ppb"
|
||||
value = "1e-9"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PPT"
|
||||
strings = "ppt"
|
||||
value = "1e-12"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PPQ"
|
||||
strings = "ppq"
|
||||
value = "1e-15"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "WH"
|
||||
strings = "Wh"
|
||||
value = "W * hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "KWH"
|
||||
strings = "kWh"
|
||||
value = "kW * hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "MWH"
|
||||
strings = "WMh"
|
||||
value = "MW * hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "GWH"
|
||||
strings = "GWh"
|
||||
value = "GW * hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "TWH"
|
||||
strings = "TWh"
|
||||
value = "TW * hour"
|
||||
unit = true
|
||||
|
||||
[[constant]]
|
||||
enum_name = "PWH"
|
||||
strings = "PWh"
|
||||
value = "PW * hour"
|
||||
unit = true
|
||||
value = "PW * hour"
|
@ -16,6 +16,7 @@ fn main() -> Result<(), ()>{
|
||||
|
||||
units::write(&Path::new(&out_dir).join("units.rs"));
|
||||
constants::write(&Path::new(&out_dir).join("constants.rs"));
|
||||
//constants::write(&Path::new("constants.rs"));
|
||||
|
||||
return Ok(());
|
||||
}
|
Reference in New Issue
Block a user