Skip to content

Commit 21440e7

Browse files
committed
WIP
0 parents  commit 21440e7

File tree

6 files changed

+351
-0
lines changed

6 files changed

+351
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

Lines changed: 205 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "typed_script"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
pest = "2.5.5"
10+
pest_derive = "2.5.5"

shell.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
pkgs.mkShell {
3+
nativeBuildInputs = with pkgs; [ rustup cargo gcc ];
4+
buildInputs = with pkgs; [
5+
clang
6+
rustfmt
7+
clippy
8+
just
9+
kube3d
10+
openssl
11+
pkgconfig
12+
python310Packages.ipython
13+
protobuf
14+
kustomize
15+
kubectl
16+
operator-sdk
17+
postgresql
18+
s3cmd
19+
minio-client
20+
argo
21+
python310Packages.mlflow
22+
kubernetes-helm
23+
grpcurl
24+
sass
25+
];
26+
27+
# Certain Rust tools won't work without this
28+
# This can also be fixed by using oxalica/rust-overlay and specifying the rust-src extension
29+
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details.
30+
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
31+
32+
# This is required to build hun-spell for cargo-spellchecker
33+
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
34+
35+
# TODO: use cargo bin path env variables instead of specific path.
36+
shellHook = ''
37+
export PATH=$PATH:~/.cargo/bin
38+
'';
39+
}

src/main.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use pest::Parser;
2+
use pest_derive::{self, Parser};
3+
4+
#[derive(Parser)]
5+
#[grammar = "typed_script.pest"]
6+
struct TSParser;
7+
8+
pub enum TSExpression {
9+
Value(TSValue)
10+
}
11+
12+
pub enum TSValue {
13+
String,
14+
Number,
15+
Boolean,
16+
}
17+
18+
pub enum TSType {
19+
String,
20+
Number,
21+
Boolean
22+
}
23+
24+
pub struct TSIdentifier(String);
25+
26+
pub enum TSAST {
27+
Value(TSValue),
28+
Expression(TSExpression),
29+
Assignment(TSIdentifier, TSExpression)
30+
}
31+
32+
pub enum TypedAst {
33+
Value(TSValue, TSType),
34+
Expression(TSExpression, TSType),
35+
Assignment(TSIdentifier, TSExpression, TSType)
36+
}
37+
38+
39+
fn main() {
40+
let parsed_res = TSParser::parse(Rule::program, "let myvar = \"test\";").unwrap();
41+
42+
let mut ast: Vec<TSAST> = vec![];
43+
44+
for rule in parsed_res{
45+
match rule.as_rule(){
46+
Rule::program => println!("{}", rule),
47+
Rule::expression => println!("{}", rule),
48+
Rule::assignment => println!("{}", rule),
49+
_ => println!("{}", rule)
50+
}
51+
}
52+
53+
}
54+
55+
fn parse_assignment(assignment: Rule::assignment) -> Result<TAST, Box<dyn std::error::Error>> {
56+
57+
let mut inner_rules = assignment.into_inner();
58+
59+
inner_rules.next();
60+
61+
let identifier = inner_rules.next().unwrap();
62+
63+
inner_rules.next();
64+
65+
let expression = inner_rules.next().unwrap();
66+
67+
println!("id: {identifier}, exp: {expression} ");
68+
69+
todo!()
70+
}

src/typed_script.pest

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
number = { ASCII_DIGIT+ }
2+
3+
string = { "\"" ~ inner ~ "\"" }
4+
5+
identifier = {
6+
ASCII_ALPHA+
7+
}
8+
9+
assignment = { "let " ~ identifier ~ " = " ~ expression ~ ";" }
10+
11+
inner = @{ char* }
12+
13+
expression = {
14+
number | string
15+
}
16+
17+
char = {
18+
!("\"" | "\\") ~ ANY
19+
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
20+
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
21+
}
22+
23+
stmt = _{ expression | assignment }
24+
25+
program = _{ SOI ~ "\n"* ~ (stmt ~ "\n"+) * ~ stmt? ~ EOI }
26+

0 commit comments

Comments
 (0)