-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from dtolnay/hack
Rewrite using proc-macro-hack
- Loading branch information
Showing
29 changed files
with
293 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
[package] | ||
name = "indoc" | ||
version = "0.1.15" | ||
version = "0.2.0" | ||
authors = ["David Tolnay <dtolnay@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
description = "Indented document literals" | ||
repository = "https://github.com/dtolnay/indoc" | ||
documentation = "https://github.com/dtolnay/indoc" | ||
keywords = ["heredoc", "nowdoc", "multiline", "string", "literal"] | ||
include = ["Cargo.toml", "src/**/*.rs"] | ||
|
||
[lib] | ||
name = "indoc" | ||
plugin = true | ||
|
||
[features] | ||
default = [] | ||
with-syntex = ["syntex", "syntex_syntax"] | ||
|
||
[dependencies] | ||
clippy = { version = "^0.*", optional = true } | ||
syntex = { version = "0.51.0", optional = true } | ||
syntex_syntax = { version = "0.51.0", optional = true } | ||
unindent = "0.1" | ||
indoc-impl = { version = "0.2", path = "impl" } | ||
proc-macro-hack = "0.3" | ||
|
||
[dev-dependencies] | ||
compiletest_rs = "0.2.4" | ||
compiletest_rs = "0.3" | ||
|
||
[workspace] | ||
members = ["impl", "unindent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "indoc-impl" | ||
version = "0.2.0" | ||
authors = ["David Tolnay <dtolnay@gmail.com>"] | ||
license = "MIT/Apache-2.0" | ||
description = "Indented document literals" | ||
repository = "https://github.com/dtolnay/indoc" | ||
documentation = "https://github.com/dtolnay/indoc" | ||
keywords = ["heredoc", "nowdoc", "multiline", "string", "literal"] | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro-hack = "0.3" | ||
quote = "0.3" | ||
syn = "0.11" | ||
unindent = { version = "0.1", path = "../unindent" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2016 Indoc Developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[macro_use] | ||
extern crate proc_macro_hack; | ||
|
||
extern crate syn; | ||
|
||
#[macro_use] | ||
extern crate quote; | ||
|
||
extern crate unindent; | ||
use unindent::*; | ||
|
||
use syn::{TokenTree, Token, Lit}; | ||
|
||
proc_macro_expr_impl! { | ||
pub fn indoc_impl(input: &str) -> String { | ||
let source = input.to_string(); | ||
|
||
let tts = syn::parse_token_trees(&source).unwrap(); | ||
|
||
if tts.len() != 1 { | ||
panic!("argument must be a single string literal, but got {} arguments", tts.len()); | ||
} | ||
|
||
let tt = tts.into_iter().next().unwrap(); | ||
|
||
let mut lit = match tt { | ||
TokenTree::Token(Token::Literal(lit)) => lit, | ||
_ => { | ||
panic!("argument must be a single string literal"); | ||
} | ||
}; | ||
|
||
match lit { | ||
Lit::Str(ref mut s, _style) => { | ||
*s = unindent(s); | ||
} | ||
Lit::ByteStr(ref mut v, _style) => { | ||
*v = unindent_bytes(v); | ||
} | ||
_ => { | ||
panic!("argument must be a single string literal"); | ||
} | ||
} | ||
|
||
quote!(#lit).parse().unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.