Stream: t-compiler/help

Topic: how can I use libsyntax by my self


Derek (Dec 09 2019 at 06:22, on Zulip):

Hi is there a way to use libsyntax by my self? I want parse some source code and get some extra information, something similar to this post.
https://stackoverflow.com/questions/26575443/how-do-i-use-the-rust-parser-libsyntax-myself
I added following to my Cargo.toml, and Call some API from rustc_lexer and libsyntax by my self, rustc_lexer works fine,
but after I add syntax, during build, I got lots of error.
[dependencies]
rustc_lexer = { path = "/home/derek/Documents/rust/rust/src/librustc_lexer" }
syntax = { path = "/home/derek/Documents/rust/rust/src/libsyntax" }

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
--> /home/derek/Documents/rust/rust/src/librustc_data_structures/lib.rs:35:1
|
35 | extern crate libc;
| ^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

it says "add #![feature(rustc_private)] to the crate attributes to enable", but there are too many errors like this, I don't want to do it manually for each file.
Is there a better way to do this, Thanks!

Charles Lew (Dec 09 2019 at 09:22, on Zulip):

You can use rustc-ap-syntax on crates.io, i guess?

oli (Dec 09 2019 at 10:42, on Zulip):

I suggest you instead use syn, which has a much more accessible API and will not break your code very two weeks ;)

Derek (Dec 10 2019 at 04:14, on Zulip):

Thank you, @oli, @Charles Lew

Last update: Apr 06 2020 at 02:50UTC