mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: 1e !
This commit is contained in:
parent
4fbd6ab408
commit
121a273788
2 changed files with 35 additions and 24 deletions
|
|
@ -335,29 +335,40 @@ pub struct Configuration {
|
|||
|
||||
impl Configuration {
|
||||
pub fn from_path (path: &impl AsRef<Path>, _watch: bool) -> Usually<Self> {
|
||||
let mut config = Self::default();
|
||||
config.path = path.as_ref().into();
|
||||
let mut dsl = read_and_leak(path.as_ref())?;
|
||||
while let Some(mut exp) = dsl.exp_next()? {
|
||||
match exp.exp_head()?.key()? {
|
||||
Some("name") => match exp.text()? {
|
||||
Some(name) => config.name = Some(name.into()),
|
||||
_ => return Err(format!("missing name definition").into())
|
||||
},
|
||||
Some("info") => match exp.text()? {
|
||||
Some(info) => config.info = Some(info.into()),
|
||||
_ => return Err(format!("missing info definition").into())
|
||||
},
|
||||
Some("keys") => match exp.text()? {
|
||||
Some(keys) => config.keys = EventMap::from_dsl(keys)?,
|
||||
_ => return Err(format!("missing keys definition").into())
|
||||
},
|
||||
Some("view") => match exp.exp_tail()? {
|
||||
Some(tail) => config.view = tail.src().into(),
|
||||
_ => return Err(format!("missing view definition").into())
|
||||
},
|
||||
Some(k) => return Err(format!("(e3) unexpected key {k:?} in {exp:?}").into()),
|
||||
None => return Err(format!("(e2) unexpected exp {exp:?}").into()),
|
||||
let mut config = Self { path: path.as_ref().into(), ..Default::default() };
|
||||
let mut dsl = read_and_leak(path.as_ref())?;
|
||||
let mut head = dsl.head()?;
|
||||
let mut tail = dsl.tail()?;
|
||||
loop {
|
||||
if let Some(exp) = head.exp()? {
|
||||
match exp.head()?.key()? {
|
||||
Some("name") => match exp.tail()?.text()? {
|
||||
Some(name) => config.name = Some(name.into()),
|
||||
_ => return Err(format!("missing name definition").into())
|
||||
},
|
||||
Some("info") => match exp.tail()?.text()? {
|
||||
Some(info) => config.info = Some(info.into()),
|
||||
_ => return Err(format!("missing info definition").into())
|
||||
},
|
||||
Some("keys") => match exp.tail()? {
|
||||
Some(keys) => config.keys = EventMap::from_dsl(&mut &keys)?,
|
||||
_ => return Err(format!("missing keys definition").into())
|
||||
},
|
||||
Some("view") => match exp.tail()? {
|
||||
Some(tail) => config.view = tail.src().into(),
|
||||
_ => return Err(format!("missing view definition").into())
|
||||
},
|
||||
Some(k) => return Err(format!("(e3) unexpected key {k:?} in {exp:?}").into()),
|
||||
None => return Err(format!("(e2) unexpected exp {exp:?}").into()),
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
if let Some(next) = tail {
|
||||
head = next.head()?;
|
||||
tail = next.tail()?;
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
Ok(config)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue