///
/// This type is a [syntax tree enum].
///
- /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
- //
- // TODO: change syntax-tree-enum link to an intra rustdoc link, currently
- // blocked on https://github.com/rust-lang/rust/issues/62833
+ /// [syntax tree enum]: crate::Expr#syntax-tree-enums
pub enum Lit {
/// A UTF-8 string literal: `"foo"`.
Str(LitStr),
/// A floating point literal: `1f64` or `1.0e10f64`.
///
- /// Must be finite. May not be infinte or NaN.
+ /// Must be finite. May not be infinite or NaN.
Float(LitFloat),
/// A boolean literal: `true` or `false`.
/// }
/// ```
#[cfg(feature = "parsing")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse<T: Parse>(&self) -> Result<T> {
self.parse_with(T::parse)
}
/// # }
/// ```
#[cfg(feature = "parsing")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_with<F: Parser>(&self, parser: F) -> Result<F::Output> {
use proc_macro2::Group;
}
}
+impl LitBool {
+ pub fn new(value: bool, span: Span) -> Self {
+ LitBool { value, span }
+ }
+
+ pub fn value(&self) -> bool {
+ self.value
+ }
+
+ pub fn span(&self) -> Span {
+ self.span
+ }
+
+ pub fn set_span(&mut self, span: Span) {
+ self.span = span;
+ }
+}
+
#[cfg(feature = "extra-traits")]
mod debug_impls {
use super::*;
use std::fmt::{self, Debug};
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitStr {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitByteStr {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitByte {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitChar {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitInt {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitFloat {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Debug for LitBool {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
}
#[cfg(feature = "clone-impls")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
impl Clone for LitRepr {
fn clone(&self) -> Self {
LitRepr {
}
#[cfg(feature = "clone-impls")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
impl Clone for LitIntRepr {
fn clone(&self) -> Self {
LitIntRepr {
}
#[cfg(feature = "clone-impls")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
impl Clone for LitFloatRepr {
fn clone(&self) -> Self {
LitFloatRepr {
macro_rules! lit_extra_traits {
($ty:ident) => {
#[cfg(feature = "clone-impls")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))]
impl Clone for $ty {
fn clone(&self) -> Self {
$ty {
}
#[cfg(feature = "extra-traits")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl PartialEq for $ty {
fn eq(&self, other: &Self) -> bool {
self.repr.token.to_string() == other.repr.token.to_string()
}
#[cfg(feature = "extra-traits")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))]
impl Hash for $ty {
fn hash<H>(&self, state: &mut H)
where
use crate::parse::{Parse, ParseStream, Result};
use proc_macro2::Punct;
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Lit {
fn parse(input: ParseStream) -> Result<Self> {
input.step(|cursor| {
))
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitStr {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Str(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Str(lit)) => Ok(lit),
_ => Err(head.error("expected string literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitByteStr {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::ByteStr(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::ByteStr(lit)) => Ok(lit),
_ => Err(head.error("expected byte string literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitByte {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Byte(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Byte(lit)) => Ok(lit),
_ => Err(head.error("expected byte literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitChar {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Char(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Char(lit)) => Ok(lit),
_ => Err(head.error("expected character literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitInt {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Int(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Int(lit)) => Ok(lit),
_ => Err(head.error("expected integer literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitFloat {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Float(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Float(lit)) => Ok(lit),
_ => Err(head.error("expected floating point literal")),
}
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for LitBool {
fn parse(input: ParseStream) -> Result<Self> {
let head = input.fork();
- match input.parse()? {
- Lit::Bool(lit) => Ok(lit),
+ match input.parse() {
+ Ok(Lit::Bool(lit)) => Ok(lit),
_ => Err(head.error("expected boolean literal")),
}
}
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitStr {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitByteStr {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitByte {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitChar {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitInt {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitFloat {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.repr.token.to_tokens(tokens);
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for LitBool {
fn to_tokens(&self, tokens: &mut TokenStream) {
let s = if self.value { "true" } else { "false" };
fn backslash_u(mut s: &str) -> (char, &str) {
if byte(s, 0) != b'{' {
- panic!("expected {{ after \\u");
+ panic!("{}", "expected { after \\u");
}
s = &s[1..];