Use custom Arc backed input
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
1ea15f0e49
commit
1ee7611981
6 changed files with 283 additions and 77 deletions
|
|
@ -24,8 +24,8 @@ pub struct TemplateAst<'input> {
|
|||
root: Vec<TemplateAstExpr<'input>>,
|
||||
}
|
||||
|
||||
impl<'input> TemplateAst<'input> {
|
||||
pub fn root(&self) -> &[TemplateAstExpr<'input>] {
|
||||
impl TemplateAst<'_> {
|
||||
pub fn root(&self) -> &[TemplateAstExpr<'_>] {
|
||||
&self.root
|
||||
}
|
||||
}
|
||||
|
|
@ -73,22 +73,22 @@ impl ModalError for AstError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'input> FromRecoverableError<Input<'input>, AstError> for AstError {
|
||||
impl FromRecoverableError<Input<'_>, AstError> for AstError {
|
||||
fn from_recoverable_error(
|
||||
token_start: &<Input<'input> as winnow::stream::Stream>::Checkpoint,
|
||||
_err_start: &<Input<'input> as winnow::stream::Stream>::Checkpoint,
|
||||
input: &Input<'input>,
|
||||
token_start: &<Input as winnow::stream::Stream>::Checkpoint,
|
||||
_err_start: &<Input as winnow::stream::Stream>::Checkpoint,
|
||||
input: &Input,
|
||||
mut e: AstError,
|
||||
) -> Self {
|
||||
e
|
||||
}
|
||||
}
|
||||
|
||||
impl<'input> AddContext<Input<'input>, AstError> for AstError {
|
||||
impl AddContext<Input<'_>, AstError> for AstError {
|
||||
fn add_context(
|
||||
mut self,
|
||||
_input: &Input<'input>,
|
||||
_token_start: &<Input<'input> as Stream>::Checkpoint,
|
||||
_input: &Input,
|
||||
_token_start: &<Input as Stream>::Checkpoint,
|
||||
context: AstError,
|
||||
) -> Self {
|
||||
self.message = context.message.or(self.message);
|
||||
|
|
@ -97,10 +97,10 @@ impl<'input> AddContext<Input<'input>, AstError> for AstError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'input> ParserError<Input<'input>> for AstError {
|
||||
impl ParserError<Input<'_>> for AstError {
|
||||
type Inner = AstError;
|
||||
|
||||
fn from_input(_input: &Input<'input>) -> Self {
|
||||
fn from_input(_input: &Input<'_>) -> Self {
|
||||
AstError::ctx()
|
||||
}
|
||||
|
||||
|
|
@ -117,24 +117,22 @@ impl<'input> ParserError<Input<'input>> for AstError {
|
|||
pub struct AstFailure {}
|
||||
|
||||
impl AstFailure {
|
||||
fn from_errors(_errors: Vec<AstError>, _input: &[TemplateToken<'_>]) -> AstFailure {
|
||||
fn from_errors(_errors: Vec<AstError>, _input: &[TemplateToken]) -> AstFailure {
|
||||
AstFailure {}
|
||||
}
|
||||
}
|
||||
|
||||
type Input<'input> = Recoverable<TokenSlice<'input, TemplateToken<'input>>, AstError>;
|
||||
type Input<'input> = Recoverable<TokenSlice<'input, TemplateToken>, AstError>;
|
||||
|
||||
impl<'i> Parser<Input<'i>, TemplateToken<'i>, AstError> for TokenKind {
|
||||
fn parse_next(&mut self, input: &mut Input<'i>) -> winnow::Result<TemplateToken<'i>, AstError> {
|
||||
impl<'input> Parser<Input<'input>, TemplateToken, AstError> for TokenKind {
|
||||
fn parse_next(&mut self, input: &mut Input<'input>) -> winnow::Result<TemplateToken, AstError> {
|
||||
winnow::token::literal(*self)
|
||||
.parse_next(input)
|
||||
.map(|t| t[0].clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse<'input>(
|
||||
input: &'input [TemplateToken<'input>],
|
||||
) -> Result<TemplateAst<'input>, AstFailure> {
|
||||
pub fn parse(input: &[TemplateToken]) -> Result<TemplateAst<'_>, AstFailure> {
|
||||
let (_remaining, val, errors) = parse_ast.recoverable_parse(TokenSlice::new(input));
|
||||
|
||||
if errors.is_empty()
|
||||
|
|
@ -148,15 +146,15 @@ pub fn parse<'input>(
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TemplateAstExpr<'input> {
|
||||
StaticContent(TemplateToken<'input>),
|
||||
StaticContent(TemplateToken),
|
||||
Interpolation {
|
||||
prev_whitespace: Option<TemplateToken<'input>>,
|
||||
wants_output: Option<TemplateToken<'input>>,
|
||||
prev_whitespace: Option<TemplateToken>,
|
||||
wants_output: Option<TemplateToken>,
|
||||
expression: Box<TemplateAstExpr<'input>>,
|
||||
post_whitespace: Option<TemplateToken<'input>>,
|
||||
post_whitespace: Option<TemplateToken>,
|
||||
},
|
||||
VariableAccess(TemplateToken<'input>),
|
||||
Invalid(&'input [TemplateToken<'input>]),
|
||||
VariableAccess(TemplateToken),
|
||||
Invalid(&'input [TemplateToken]),
|
||||
}
|
||||
|
||||
fn parse_ast<'input>(input: &mut Input<'input>) -> Result<Vec<TemplateAstExpr<'input>>, AstError> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue