Compare commits
No commits in common. "b0795f2dd48c555f29cbf64e20fab444cda0a719" and "da4990107cf7a8e648788e03f36c70efeafda62d" have entirely different histories.
b0795f2dd4
...
da4990107c
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -922,12 +922,21 @@ dependencies = [
|
|||||||
"peg",
|
"peg",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"radix_trie",
|
"radix_trie",
|
||||||
|
"schala-lang-codegen",
|
||||||
"schala-repl",
|
"schala-repl",
|
||||||
"stopwatch",
|
"stopwatch",
|
||||||
"take_mut",
|
"take_mut",
|
||||||
"test-case",
|
"test-case",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schala-lang-codegen"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"quote 0.6.13",
|
||||||
|
"syn 0.15.44",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schala-repl"
|
name = "schala-repl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -9,7 +9,7 @@ resolver = "2"
|
|||||||
getopts = "0.2.21"
|
getopts = "0.2.21"
|
||||||
|
|
||||||
schala-repl = { path = "schala-repl" }
|
schala-repl = { path = "schala-repl" }
|
||||||
schala-lang = { path = "schala-lang" }
|
schala-lang = { path = "schala-lang/language" }
|
||||||
# maaru-lang = { path = "maaru" }
|
# maaru-lang = { path = "maaru" }
|
||||||
# rukka-lang = { path = "rukka" }
|
# rukka-lang = { path = "rukka" }
|
||||||
# robo-lang = { path = "robo" }
|
# robo-lang = { path = "robo" }
|
||||||
|
13
schala-lang/codegen/Cargo.toml
Normal file
13
schala-lang/codegen/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "schala-lang-codegen"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["greg <greg.shuflin@protonmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = { version = "0.15.12", features = ["full", "extra-traits", "fold"] }
|
||||||
|
quote = "0.6.8"
|
53
schala-lang/codegen/src/lib.rs
Normal file
53
schala-lang/codegen/src/lib.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#![feature(box_patterns)]
|
||||||
|
#![recursion_limit="128"]
|
||||||
|
extern crate proc_macro;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate quote;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate syn;
|
||||||
|
|
||||||
|
use self::proc_macro::TokenStream;
|
||||||
|
use self::syn::fold::Fold;
|
||||||
|
|
||||||
|
struct RecursiveDescentFn {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Fold for RecursiveDescentFn {
|
||||||
|
fn fold_item_fn(&mut self, mut i: syn::ItemFn) -> syn::ItemFn {
|
||||||
|
let box block = i.block;
|
||||||
|
let ident = &i.ident;
|
||||||
|
|
||||||
|
let new_block: syn::Block = parse_quote! {
|
||||||
|
{
|
||||||
|
let next_token_before_parse = self.token_handler.peek();
|
||||||
|
let record = ParseRecord {
|
||||||
|
production_name: stringify!(#ident).to_string(),
|
||||||
|
next_token: format!("{}", next_token_before_parse.to_string_with_metadata()),
|
||||||
|
level: self.parse_level,
|
||||||
|
};
|
||||||
|
self.parse_level += 1;
|
||||||
|
self.parse_record.push(record);
|
||||||
|
let result = { #block };
|
||||||
|
|
||||||
|
if self.parse_level != 0 {
|
||||||
|
self.parse_level -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.map_err(|mut parse_error: ParseError| {
|
||||||
|
parse_error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
i.block = Box::new(new_block);
|
||||||
|
i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn recursive_descent_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
|
let input: syn::ItemFn = parse_macro_input!(item as syn::ItemFn);
|
||||||
|
let mut folder = RecursiveDescentFn {};
|
||||||
|
let output = folder.fold_item_fn(input);
|
||||||
|
TokenStream::from(quote!(#output))
|
||||||
|
}
|
@ -18,7 +18,8 @@ assert_matches = "1.5"
|
|||||||
peg = { git = "https://github.com/kevinmehall/rust-peg", rev = "960222580c8da25b17d32c2aae6f52f902728b62" }
|
peg = { git = "https://github.com/kevinmehall/rust-peg", rev = "960222580c8da25b17d32c2aae6f52f902728b62" }
|
||||||
|
|
||||||
|
|
||||||
schala-repl = { path = "../schala-repl" }
|
schala-lang-codegen = { path = "../codegen" }
|
||||||
|
schala-repl = { path = "../../schala-repl" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-case = "1.2.0"
|
test-case = "1.2.0"
|
@ -7,6 +7,7 @@
|
|||||||
//! `ProgrammingLanguageInterface` and the chain of compiler passes for it.
|
//! `ProgrammingLanguageInterface` and the chain of compiler passes for it.
|
||||||
|
|
||||||
extern crate derivative;
|
extern crate derivative;
|
||||||
|
extern crate schala_lang_codegen;
|
||||||
extern crate schala_repl;
|
extern crate schala_repl;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
Loading…
Reference in New Issue
Block a user