Skip to content

Commit

Permalink
work in progress...
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Oct 30, 2024
1 parent 3554a49 commit 0750735
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 136 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.buildScripts.enable": true
}
38 changes: 0 additions & 38 deletions examples/clean_up_cans.k

This file was deleted.

10 changes: 10 additions & 0 deletions examples/simple.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn wave(limb: string, joint: number, amount: number) : "Wave a hand back and forth" {
let pos = get_position(limb: limb, joint: joint);
let pos = set_position(limb: limb, joint: joint, pos: pos + amount);
let pos = set_position(limb: limb, joint: joint, pos: pos - amount);
return pos;
}

fn main() : "Wave a hand back and forth a few times" {
wave(limb: "right_arm", joint: 0, amount: 45deg);
}
13 changes: 10 additions & 3 deletions klang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ name = "klang"
version = "0.1.0"
authors = ["K-Scale Labs"]
edition = "2021"
build = "build.rs"

[dependencies]

pest = "2.5"
pest_derive = "2.5"
pest = "^2.5"
pest_derive = "^2.5"
thiserror = "1.0"
lazy_static = "1.4.0"
lazy_static = "^1.4.0"
prost = "0.13"
prost-types = "0.13"

[build-dependencies]

prost-build = "^0.13.3"

[[bin]]

Expand Down
17 changes: 17 additions & 0 deletions klang/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use prost_build;

Check failure on line 1 in klang/build.rs

View workflow job for this annotation

GitHub Actions / Lints

this import is redundant
use std::env;
use std::path::PathBuf;

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto");
std::fs::create_dir_all(&out_dir).unwrap();

let mut config = prost_build::Config::new();
config.out_dir(&out_dir);
config.retain_enum_prefix();
config.enable_type_names();

config
.compile_protos(&["src/proto/ast.proto"], &["src/proto/"])
.unwrap();
}
85 changes: 0 additions & 85 deletions klang/src/klang.pest

This file was deleted.

16 changes: 7 additions & 9 deletions klang/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use pest::Parser;
use pest_derive::Parser;
use std::fs;
use std::path::Path;

#[derive(Parser)]
#[grammar = "klang.pest"] // relative path to your Pest grammar file
struct KlangParser;
mod parser;

pub fn read_and_parse_file(file_path: &Path) -> Result<String, String> {
// Read the file contents
Expand All @@ -20,9 +16,9 @@ pub fn read_and_parse_file(file_path: &Path) -> Result<String, String> {
}
};

// Parse the file contents using the KlangParser
let parsed_file = match KlangParser::parse(Rule::program, &unparsed_file) {
Ok(parsed) => format!("{:#?}", parsed),
// Parse the file contents using our new parser
let ast = match PestParser::parse(&unparsed_file) {
Ok(ast) => ast,
Err(e) => {
return Err(format!(
"Error parsing file '{}': {}",
Expand All @@ -32,5 +28,7 @@ pub fn read_and_parse_file(file_path: &Path) -> Result<String, String> {
}
};

Ok(parsed_file)
let program = parse_program(ast.next().unwrap());

Ok(format!("{:#?}", program))
}
Loading

0 comments on commit 0750735

Please sign in to comment.