-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: John-John Tedro <[email protected]>
- Loading branch information
Showing
33 changed files
with
662 additions
and
75 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use super::prelude::*; | ||
use super::Eq; | ||
|
||
/// An `= ...` e.g. inside an attribute `#[doc = ...]`. | ||
/// | ||
/// To get unparsed tokens use `EqValue<TokenStream>`. | ||
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Parse, Spanned)] | ||
pub struct EqValue<T> { | ||
/// The `=` token. | ||
pub eq: Eq, | ||
/// The remainder. | ||
pub value: T, | ||
} | ||
|
||
/// Parses `[{( ... )}]` ensuring that the delimiter is balanced. | ||
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)] | ||
pub struct Group { | ||
/// The opening delimiter. | ||
pub open: ast::Token, | ||
/// The content between the delimiters. | ||
pub content: TokenStream, | ||
/// The closing delimiter. | ||
pub close: ast::Token, | ||
} | ||
|
||
impl Parse for Group { | ||
fn parse(parser: &mut Parser) -> compile::Result<Self> { | ||
let mut level = 1; | ||
let open = parser.next()?; | ||
|
||
let delim = match open.kind { | ||
ast::Kind::Open(delim) => delim, | ||
_ => { | ||
return Err(compile::Error::expected(open, Expectation::OpenDelimiter)); | ||
} | ||
}; | ||
|
||
let close; | ||
|
||
let mut stream = Vec::new(); | ||
|
||
loop { | ||
let token = parser.next()?; | ||
|
||
match token.kind { | ||
ast::Kind::Open(..) => level += 1, | ||
ast::Kind::Close(actual) => { | ||
level -= 1; | ||
|
||
if level == 0 { | ||
if actual != delim { | ||
return Err(compile::Error::new( | ||
open, | ||
ParseErrorKind::ExpectedMacroCloseDelimiter { | ||
actual: token.kind, | ||
expected: ast::Kind::Close(delim), | ||
}, | ||
)); | ||
} | ||
|
||
close = token; | ||
break; | ||
} | ||
} | ||
_ => (), | ||
} | ||
|
||
stream.push(token); | ||
} | ||
|
||
Ok(Self { | ||
open, | ||
content: TokenStream::from(stream), | ||
close, | ||
}) | ||
} | ||
} |
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.