Skip to content

Commit

Permalink
Simplify parsing of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jul 27, 2017
1 parent 5cc1baa commit da77a1a
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 255 deletions.
19 changes: 19 additions & 0 deletions src/libsyntax/ast.rs
Expand Up @@ -153,6 +153,19 @@ pub enum PathParameters {
Parenthesized(ParenthesizedParameterData),
}

impl PathParameters {
pub fn span(&self, fallback: Span) -> Span {
match *self {
AngleBracketed(ref data) => {
data.lifetimes.get(0).map(|x| x.span).or_else(||
data.types.get(0).map(|x| x.span)).or_else(||
data.bindings.get(0).map(|x| x.span)).unwrap_or(fallback)
}
Parenthesized(ref data) => data.span
}
}
}

/// A path like `Foo<'a, T>`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)]
pub struct AngleBracketedParameterData {
Expand All @@ -173,6 +186,12 @@ impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
}
}

impl Into<Option<P<PathParameters>>> for ParenthesizedParameterData {
fn into(self) -> Option<P<PathParameters>> {
Some(P(PathParameters::Parenthesized(self)))
}
}

/// A path like `Foo(A,B) -> C`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ParenthesizedParameterData {
Expand Down

0 comments on commit da77a1a

Please sign in to comment.