Initial commit for frontend
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
47
Cargo.lock
generated
Normal file
47
Cargo.lock
generated
Normal file
@@ -0,0 +1,47 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "comlexr"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "comlexr"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0.92"
|
||||
quote = "1.0.38"
|
||||
syn = { version = "2.0.96", features = ["full"] }
|
||||
146
src/lib.rs
Normal file
146
src/lib.rs
Normal file
@@ -0,0 +1,146 @@
|
||||
use syn::{bracketed, parse::Parse, punctuated::Punctuated, token, Token};
|
||||
|
||||
struct Command {
|
||||
program: Program,
|
||||
args: Option<Punctuated<Arg, Token![,]>>,
|
||||
}
|
||||
|
||||
impl Parse for Command {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let program = input.parse()?;
|
||||
|
||||
if input.is_empty() {
|
||||
Ok(Command {
|
||||
program,
|
||||
args: None,
|
||||
})
|
||||
} else {
|
||||
_ = input.parse::<Token![,]>()?;
|
||||
Ok(Command {
|
||||
program,
|
||||
args: Some(input.parse_terminated(Arg::parse, Token![,])?),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Program(syn::LitStr);
|
||||
|
||||
impl Parse for Program {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.parse().map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
enum Arg {
|
||||
Expression(syn::Expr),
|
||||
ForIter {
|
||||
for_key: Token![for],
|
||||
expr: syn::Expr,
|
||||
},
|
||||
ForInIterMulti {
|
||||
for_iter: ForIter,
|
||||
arrow_token: Token![=>],
|
||||
args: MultiArg,
|
||||
},
|
||||
ForInIterSingle {
|
||||
for_iter: ForIter,
|
||||
arrow_token: Token![=>],
|
||||
arg: SingleArg,
|
||||
},
|
||||
IfLetMulti {
|
||||
if_let: IfLet,
|
||||
arrow_token: Token![=>],
|
||||
args: MultiArg,
|
||||
},
|
||||
IfLetSingle {
|
||||
if_let: IfLet,
|
||||
arrow_token: Token![=>],
|
||||
arg: SingleArg,
|
||||
},
|
||||
IfMulti {
|
||||
expr: syn::Expr,
|
||||
arrow_token: Token![=>],
|
||||
args: MultiArg,
|
||||
},
|
||||
IfSingle {
|
||||
expr: syn::Expr,
|
||||
arrow_token: Token![=>],
|
||||
arg: SingleArg,
|
||||
},
|
||||
}
|
||||
|
||||
impl Parse for Arg {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.parse()
|
||||
}
|
||||
}
|
||||
|
||||
struct Pattern(syn::Pat);
|
||||
|
||||
impl Parse for Pattern {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.call(syn::Pat::parse_single).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
struct ForIter {
|
||||
for_token: Token![for],
|
||||
pattern: Pattern,
|
||||
in_token: Token![in],
|
||||
iter: syn::Expr,
|
||||
}
|
||||
|
||||
impl Parse for ForIter {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
Ok(ForIter {
|
||||
for_token: input.parse()?,
|
||||
pattern: input.parse()?,
|
||||
in_token: input.parse()?,
|
||||
iter: input.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct IfLet {
|
||||
if_token: Token![if],
|
||||
let_token: Token![let],
|
||||
pattern: Pattern,
|
||||
eq_token: Token![=],
|
||||
expr: syn::Expr,
|
||||
}
|
||||
|
||||
impl Parse for IfLet {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
Ok(IfLet {
|
||||
if_token: input.parse()?,
|
||||
let_token: input.parse()?,
|
||||
pattern: input.parse()?,
|
||||
eq_token: input.parse()?,
|
||||
expr: input.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct SingleArg(syn::Expr);
|
||||
|
||||
impl Parse for SingleArg {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
input.parse().map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
struct MultiArg {
|
||||
bracket: token::Bracket,
|
||||
args: Punctuated<SingleArg, Token![,]>,
|
||||
}
|
||||
|
||||
impl Parse for MultiArg {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let args;
|
||||
Ok(MultiArg {
|
||||
bracket: bracketed!(args in input),
|
||||
args: input.parse_terminated(SingleArg::parse, Token![,])?,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user