-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0d2ddb1
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "translator" | ||
version = "0.1.0" | ||
authors = ["Jeremy Mill <jeremymill@gmail.com>"] | ||
|
||
[dependencies] | ||
syn = "0.12.12" | ||
quote = "0.3.15" | ||
proc-macro2 = "0.2.2" | ||
|
||
[lib] | ||
proc-macro = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Jeremy Mill | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": "." | ||
}, | ||
{ | ||
"path": "C:\\Users\\bobo\\Documents\\TranslatorTest" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
extern crate proc_macro; | ||
extern crate proc_macro2; | ||
extern crate syn; | ||
#[macro_use] | ||
extern crate quote; | ||
|
||
use proc_macro::TokenStream; | ||
use proc_macro2::TokenNode; | ||
use syn::Data; | ||
|
||
#[proc_macro_derive(Translate)] | ||
pub fn translate(input: TokenStream) -> TokenStream { | ||
// Construct a string representation of the type definition | ||
println!("inside of translate"); | ||
//let s = input.to_string(); | ||
|
||
// Parse the string representation | ||
let ast = syn::parse(input).unwrap(); | ||
|
||
// Build the impl | ||
let gen = impl_translate(ast); | ||
|
||
// Return the generated impl | ||
gen.parse().unwrap() | ||
} | ||
|
||
fn impl_translate(ast: syn::DeriveInput) -> quote::Tokens { | ||
// let name = ast.ident; | ||
|
||
println!("name is: {}", ast.ident); | ||
let mut is_reprc: bool = false; | ||
//determine if this struct is repr c | ||
for attr in ast.attrs { | ||
for token in attr.tts.into_iter() { | ||
match token.kind { | ||
TokenNode::Group(_, ts) => { | ||
for t in ts.into_iter() { | ||
match t.kind { | ||
TokenNode::Term(t) => { | ||
is_reprc = t.as_str() == "C"; | ||
}, | ||
_ => {} | ||
} | ||
} | ||
} | ||
_ => {} | ||
}; | ||
//println!("token: {}", token.span); | ||
|
||
} | ||
//println!("attr: {}", attr.tts); | ||
} | ||
if is_reprc { | ||
match ast.data { | ||
Data::Struct(ds) => { | ||
//i'm here (https://dtolnay.github.io/syn/syn/struct.DataStruct.html) | ||
//figuring out how to iterate through struct fields | ||
//so far everything is named? | ||
match ds.fields { | ||
syn::Fields::Named(_) => {println!("named")}, | ||
syn::Fields::Unnamed(_) => {println!("unnamed")}, | ||
syn::Fields::Unit => {println!("unit")} | ||
} | ||
println!("it's a struct!"); | ||
}, | ||
_ => {} | ||
} | ||
} | ||
|
||
quote! { | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |