mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-10-07 09:03:30 +00:00
Factor out a constructor from LitStr to QualifiedName
This commit is contained in:
parent
8f822ad8b7
commit
50d9d69ef5
@ -7,6 +7,18 @@ pub struct QualifiedName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl QualifiedName {
|
impl QualifiedName {
|
||||||
|
pub fn parse_quoted(lit: &LitStr) -> Result<Self> {
|
||||||
|
if lit.value().is_empty() {
|
||||||
|
let segments = Vec::new();
|
||||||
|
Ok(QualifiedName { segments })
|
||||||
|
} else {
|
||||||
|
lit.parse_with(|input: ParseStream| {
|
||||||
|
let allow_raw = false;
|
||||||
|
parse_unquoted(input, allow_raw)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
|
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
|
||||||
let allow_raw = true;
|
let allow_raw = true;
|
||||||
parse_unquoted(input, allow_raw)
|
parse_unquoted(input, allow_raw)
|
||||||
@ -15,15 +27,7 @@ impl QualifiedName {
|
|||||||
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
|
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
|
||||||
if input.peek(LitStr) {
|
if input.peek(LitStr) {
|
||||||
let lit: LitStr = input.parse()?;
|
let lit: LitStr = input.parse()?;
|
||||||
if lit.value().is_empty() {
|
Self::parse_quoted(&lit)
|
||||||
let segments = Vec::new();
|
|
||||||
Ok(QualifiedName { segments })
|
|
||||||
} else {
|
|
||||||
lit.parse_with(|input: ParseStream| {
|
|
||||||
let allow_raw = false;
|
|
||||||
parse_unquoted(input, allow_raw)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Self::parse_unquoted(input)
|
Self::parse_unquoted(input)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user