Merge pull request #41 from alexcrichton/unstable
Span::unstable to expose the proc_macro::Span
diff --git a/.travis.yml b/.travis.yml
index 44570fd..e5c59af 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,7 @@
matrix:
include:
- - rust: 1.18.0
+ - rust: 1.15.0
- rust: stable
- rust: beta
- rust: nightly
diff --git a/src/lib.rs b/src/lib.rs
index 62fa595..26d3244 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -176,13 +176,13 @@
#[cfg(procmacro2_unstable)]
pub fn start(&self) -> LineColumn {
let imp::LineColumn{ line, column } = self.0.start();
- LineColumn { line, column }
+ LineColumn { line: line, column: column }
}
#[cfg(procmacro2_unstable)]
pub fn end(&self) -> LineColumn {
let imp::LineColumn{ line, column } = self.0.end();
- LineColumn { line, column }
+ LineColumn { line: line, column: column }
}
#[cfg(procmacro2_unstable)]
diff --git a/src/stable.rs b/src/stable.rs
index 9e69791..d892ae5 100644
--- a/src/stable.rs
+++ b/src/stable.rs
@@ -54,7 +54,6 @@
fn get_cursor(src: &str) -> Cursor {
Cursor {
rest: src,
- off: 0,
}
}
@@ -313,15 +312,26 @@
}
#[derive(Clone, Copy, Debug)]
-pub struct Span { lo: u32, hi: u32 }
+pub struct Span {
+ #[cfg(procmacro2_unstable)]
+ lo: u32,
+ #[cfg(procmacro2_unstable)]
+ hi: u32,
+}
impl Span {
+ #[cfg(not(procmacro2_unstable))]
+ pub fn call_site() -> Span {
+ Span {}
+ }
+
+ #[cfg(procmacro2_unstable)]
pub fn call_site() -> Span {
Span { lo: 0, hi: 0 }
}
pub fn def_site() -> Span {
- Span { lo: 0, hi: 0 }
+ Span::call_site()
}
#[cfg(procmacro2_unstable)]
@@ -568,6 +578,16 @@
|trees| ::TokenStream(TokenStream { inner: trees })
));
+#[cfg(not(procmacro2_unstable))]
+fn token_tree(input: Cursor) -> PResult<TokenTree> {
+ let (input, kind) = token_kind(input)?;
+ Ok((input, TokenTree {
+ span: ::Span(Span {}),
+ kind: kind,
+ }))
+}
+
+#[cfg(procmacro2_unstable)]
fn token_tree(input: Cursor) -> PResult<TokenTree> {
let input = skip_whitespace(input);
let lo = input.off;
diff --git a/src/strnom.rs b/src/strnom.rs
index 558be8e..2f9e73f 100644
--- a/src/strnom.rs
+++ b/src/strnom.rs
@@ -9,10 +9,18 @@
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Cursor<'a> {
pub rest: &'a str,
+ #[cfg(procmacro2_unstable)]
pub off: u32,
}
impl<'a> Cursor<'a> {
+ #[cfg(not(procmacro2_unstable))]
+ pub fn advance(&self, amt: usize) -> Cursor<'a> {
+ Cursor {
+ rest: &self.rest[amt..],
+ }
+ }
+ #[cfg(procmacro2_unstable)]
pub fn advance(&self, amt: usize) -> Cursor<'a> {
Cursor {
rest: &self.rest[amt..],
diff --git a/tests/test.rs b/tests/test.rs
index 2de120a..6442ba6 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1,6 +1,13 @@
extern crate proc_macro2;
-use proc_macro2::{Term, Literal, TokenStream, TokenNode, Span};
+use proc_macro2::{Term, Literal, TokenStream};
+
+#[cfg(procmacro2_unstable)]
+use proc_macro2::TokenNode;
+
+#[cfg(procmacro2_unstable)]
+#[cfg(not(feature = "unstable"))]
+use proc_macro2::Span;
#[test]
fn symbols() {