]> git.proxmox.com Git - rustc.git/blame - src/libproc_macro_tokens/parse.rs
New upstream version 1.15.0+dfsg1
[rustc.git] / src / libproc_macro_tokens / parse.rs
CommitLineData
9e0c209e
SL
1// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Parsing utilities for writing procedural macros.
12
13extern crate syntax;
14
15use syntax::parse::{ParseSess, filemap_to_tts};
16use syntax::tokenstream::TokenStream;
17
476ff2be 18/// Map a string to tts, using a made-up filename. For example, `lex("15")` will return a
9e0c209e
SL
19/// TokenStream containing the literal 15.
20pub fn lex(source_str: &str) -> TokenStream {
21 let ps = ParseSess::new();
22 TokenStream::from_tts(filemap_to_tts(&ps,
476ff2be 23 ps.codemap().new_filemap("<procmacro_lex>".to_string(),
9e0c209e
SL
24 None,
25 source_str.to_owned())))
26}