Skip to content

Commit

Permalink
yaml parsing started (#17)
Browse files Browse the repository at this point in the history
this is pretty much a nothing commit, just practiced some yaml
  • Loading branch information
coffeebe4code authored Sep 20, 2023
1 parent e198aa2 commit dd18e33
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
main*
main.o

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ members = [
"object",
"linker",
"ast",
"project",
"ty",
"ir",
"e2e",
]
Expand Down
9 changes: 5 additions & 4 deletions docs/project.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
type: Project
name:
details:

type: project
name:
targets:
-
hooks:
---
type: Exe
name: ty
Expand Down
10 changes: 10 additions & 0 deletions project/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "project"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1", features = [ "derive" ] }
serde_yaml = "0"
48 changes: 48 additions & 0 deletions project/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use serde::{Deserialize, Serialize};
use serde_yaml::{self};

#[derive(Serialize, Deserialize, Debug)]
pub struct Recipe {
kind: String,
name: String,
details: serde_yaml::Value,
}

pub struct ProjectConfig {}

impl ProjectConfig {
pub fn new() -> ProjectConfig {
ProjectConfig {}
}
pub fn parse_multi_yaml(&mut self, file: String) -> () {
for document in serde_yaml::Deserializer::from_str(&file) {
let v = Recipe::deserialize(document).unwrap();
println!("{:?}", v);
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let yaml = "\
kind: project\n\
name: SDL\n\
details:\n\
- ref: help\n\
- me\n\
---\n\
kind: target\n\
name: sdl_exe\n\
details:\n\
- help\n\
- me\n\
"
.to_string();
let mut project = ProjectConfig::new();
project.parse_multi_yaml(yaml);
}
}
8 changes: 8 additions & 0 deletions ty/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "ty"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions ty/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit dd18e33

Please sign in to comment.