cargo new

This commit is contained in:
nora 2022-10-16 21:48:09 +02:00
parent f86f37810c
commit f7964cf17e
No known key found for this signature in database
9 changed files with 306 additions and 0 deletions

5
.gitignore vendored
View file

@ -4,3 +4,8 @@
# These are backup files generated by rustfmt
**/*.rs.bk
# Added by cargo
/target

3
.rustfmt.toml Normal file
View file

@ -0,0 +1,3 @@
imports_granularity = "Crate"
newline_style = "Unix"
group_imports = "StdExternalCrate"

183
Cargo.lock generated Normal file
View file

@ -0,0 +1,183 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ahash"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
dependencies = [
"const-random",
]
[[package]]
name = "beef"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chumsky"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d02796e4586c6c41aeb68eae9bfb4558a522c35f1430c14b40136c3706e09e4"
dependencies = [
"ahash",
]
[[package]]
name = "const-random"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f590d95d011aa80b063ffe3253422ed5aa462af4e9867d43ce8337562bac77c4"
dependencies = [
"const-random-macro",
"proc-macro-hack",
]
[[package]]
name = "const-random-macro"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "615f6e27d000a2bffbc7f2f6a8669179378fa27ee4d0a509e985dfc0a7defb40"
dependencies = [
"getrandom",
"lazy_static",
"proc-macro-hack",
"tiny-keccak",
]
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "getrandom"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]]
name = "logos"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
dependencies = [
"logos-derive",
]
[[package]]
name = "logos-derive"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
"syn",
]
[[package]]
name = "nodra"
version = "0.1.0"
dependencies = [
"chumsky",
"logos",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro2"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex-syntax"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "syn"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
dependencies = [
"crunchy",
]
[[package]]
name = "unicode-ident"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "nodra"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chumsky = "0.8.0"
logos = "0.12.1"

30
src/ast.rs Normal file
View file

@ -0,0 +1,30 @@
use std::ops::Range;
type Span = Range<usize>;
type Ident = String;
pub enum Item {
Fn(Fn),
}
pub enum FnKind {
Fn,
Task,
}
struct Fn {
pub kind: FnKind,
pub span: Span,
}
pub enum Expr {
Int(u64),
Ident(Ident),
Binary(BinaryOp, Box<Expr>, Box<Expr>, Span),
Assign(Ident, Box<Expr>, Span),
}
pub enum BinaryOp {
Add,
Sub,
}

31
src/lexer.rs Normal file
View file

@ -0,0 +1,31 @@
#[derive(Debug, Clone, PartialEq, Eq, Hash, logos::Logos)]
pub enum Token {
#[token("+")]
Plus,
#[token("-")]
Minus,
#[token("=")]
Eq,
#[token(";")]
Semi,
#[token("(")]
POpen,
#[token(")")]
PClose,
#[token("{")]
BOpen,
#[token("}")]
BClose,
#[regex(r"\d+", |lex| lex.slice().parse())]
Int(u64),
#[regex(r"[a-zA-Z_]\w+", |lex| lex.slice().to_string())]
Ident(String),
#[token("fn")]
Fn,
#[token("let")]
Let,
#[token("task")]
Task,
#[error]
Error,
}

3
src/lib.rs Normal file
View file

@ -0,0 +1,3 @@
mod ast;
mod lexer;
mod parser;

3
src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

38
src/parser.rs Normal file
View file

@ -0,0 +1,38 @@
use chumsky::{prelude::*, Parser};
use crate::{
ast::{Expr, Item},
lexer::Token,
};
fn expr() -> impl Parser<Token, Expr, Error = Simple<Token>> {
recursive(|expr| {
let value = select! {
Token::Int(int) => Expr::Int(int),
Token::Ident(ident) => Expr::Ident(ident),
}
.boxed();
let ident = select! {
Token::Ident(ident) => ident
}
.boxed();
let let_expr = just(Token::Let)
.ignore_then(ident.clone())
.then_ignore(just(Token::Eq))
.then(expr.clone())
.then_ignore(just(Token::Semi))
.map_with_span(|(name, value): (String, Expr), span| {
Expr::Assign(name, Box::new(value), span)
})
.boxed();
value.or(let_expr)
})
.boxed()
}
fn item() -> impl Parser<Token, Item, Error = Simple<Token>> {
todo()
}