Skip to content
Snippets Groups Projects
Commit 52fdbbb0 authored by Per's avatar Per
Browse files

fixed parsing

parents
No related branches found
No related tags found
No related merge requests found
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cargo run --example main",
"type": "shell",
"command": "cargo run --example main",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "cargo run --example trust",
"type": "shell",
"command": "cargo run --example trust",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$rustc"
]
}
]
}
\ No newline at end of file
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "proc-collect"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[package]
name = "proc-collect"
version = "0.1.0"
authors = ["pln <Per Lindgren>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
proc-macro = true
[dependencies]
quote = "1.0.2"
proc-macro2 = "1.0"
[dependencies.syn]
version = "1.0.14"
features = ["full", "extra-traits"]
use proc_collect::*;
#[trust]
mod kalleanka {
fn hello() {
ext_hello();
}
#[entry]
fn entry() {}
#[interrupt]
fn interrupt() {}
#[exception]
fn exception() {}
}
fn ext_hello() {
println!("hello");
}
fn main() {
hello();
}
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::{quote, ToTokens, TokenStreamExt};
use std::fs::{File, OpenOptions};
use std::io::prelude::*;
use std::iter::FromIterator;
use syn::parse::{Parse, ParseStream};
use syn::{parse_macro_input, Attribute, Ident, Item, ItemMod, Result, Token};
// use syn::{parse_macro_input, Attribute, Ident, ItemMod, Result, Token};
#[proc_macro_attribute]
pub fn entry(_args: TokenStream, input: TokenStream) -> TokenStream {
let items = parse_macro_input!(input as FnItem).items;
(quote! { #(#items)* }).into()
}
#[proc_macro_attribute]
pub fn interrupt(_args: TokenStream, input: TokenStream) -> TokenStream {
input
}
#[proc_macro_attribute]
pub fn exception(_args: TokenStream, input: TokenStream) -> TokenStream {
input
}
#[derive(Debug)]
struct TrustMod {
items: Vec<Item>,
}
impl Parse for TrustMod {
fn parse(input: ParseStream) -> Result<Self> {
let module: ItemMod = input.parse()?;
match module.content {
Some((_, items)) => Ok(TrustMod { items }),
_ => panic!("illegal trust module"),
}
}
}
#[proc_macro_attribute]
pub fn trust(_args: TokenStream, input: TokenStream) -> TokenStream {
let items = parse_macro_input!(input as TrustMod).items;
(quote! { #(#items)* }).into()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment