Skip to main content
Sign in
Snippets Groups Projects
Commit 430d9f87 authored by David Renshaw's avatar David Renshaw
Browse files

syn example

parent b071553b
No related branches found
No related tags found
No related merge requests found
Cargo.lock
\ No newline at end of file
# Cargo.toml
[package]
name = "test-syn"
version = "0.0.1"
[dependencies.syn]
git = "https://github.com/dtolnay/syn"
features = ["parsing", "full"]
[[bin]]
name = "parse_file"
path = "parse_file.rs"
Make sure you have cargo-seer installed:
```
cargo install seer --git https://github.com/dwrensha/seer
```
Then run seer in this directory, with:
```
RUSTFLAGS="-Z always-encode-mir" CFG_COMPILER_HOST_TRIPLE=x86_64-unknown-linux-gnu XARGO_RUST_SRC=/path/to/rust/repo/src xargo seer --target x86_64-unknown-linux-gnu
```
See https://github.com/japaric/xargo/issues/125#issuecomment-328300943 for more discussion about
why all these special options are needed.
\ No newline at end of file
# Xargo.toml
[dependencies]
std = {features = ["panic_unwind", "jemalloc"]}
[target.x86_64-unknown-linux-gnu.dependencies.term]
stage=1
[target.x86_64-unknown-linux-gnu.dependencies.proc_macro]
stage=2
\ No newline at end of file
extern crate syn;
fn main() {
use std::io::Read;
let mut data: Vec<u8> = vec![0; 12];
let mut stdin = ::std::io::stdin();
stdin.read_exact(&mut data[..]).unwrap();
for idx in 0..data.len() {
if data[idx] > 127 {
return; // avoid invalid utf8 by exiting early
}
}
let mut buf = String::new();
{
let buf_bytes = unsafe { buf.as_mut_vec() };
for idx in 0..data.len() {
buf_bytes.push(data[idx]);
}
}
let _ = syn::parse_file(&buf);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment