Remove unnecessary Clone bounds
This commit is contained in:
parent
0099277644
commit
b291619d10
9 changed files with 32 additions and 33 deletions
|
|
@ -6,7 +6,6 @@
|
||||||
//! made public later.
|
//! made public later.
|
||||||
|
|
||||||
// TODO Turn multiple calls to subparsers into clone-s
|
// TODO Turn multiple calls to subparsers into clone-s
|
||||||
// TODO Remove unnecessary +Clone-s and 'static-s
|
|
||||||
|
|
||||||
mod basic;
|
mod basic;
|
||||||
mod expr;
|
mod expr;
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,17 @@ pub type Error = Simple<char, Span>;
|
||||||
|
|
||||||
// TODO https://github.com/rust-lang/rust/issues/63063
|
// TODO https://github.com/rust-lang/rust/issues/63063
|
||||||
|
|
||||||
fn inline() -> impl Parser<char, (), Error = Error> + Clone {
|
fn inline() -> impl Parser<char, (), Error = Error> {
|
||||||
filter(|c: &char| c.is_whitespace() && *c != '\n')
|
filter(|c: &char| c.is_whitespace() && *c != '\n')
|
||||||
.repeated()
|
.repeated()
|
||||||
.to(())
|
.to(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn newline() -> impl Parser<char, (), Error = Error> + Clone {
|
fn newline() -> impl Parser<char, (), Error = Error> {
|
||||||
just('\n').to(())
|
just('\n').to(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn line() -> impl Parser<char, Line, Error = Error> + Clone {
|
fn line() -> impl Parser<char, Line, Error = Error> {
|
||||||
let empty = newline().to(Line::Empty);
|
let empty = newline().to(Line::Empty);
|
||||||
|
|
||||||
let comment = just('#')
|
let comment = just('#')
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ fn atom(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn left_assoc(
|
fn left_assoc(
|
||||||
op: impl Parser<char, BinOp, Error = Error> + Clone + 'static,
|
op: impl Parser<char, BinOp, Error = Error> + 'static,
|
||||||
over: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
over: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> BoxedParser<'static, char, Expr, Error> {
|
) -> BoxedParser<'static, char, Expr, Error> {
|
||||||
let op_over = space()
|
let op_over = space()
|
||||||
|
|
@ -73,7 +73,7 @@ fn left_assoc(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn right_assoc(
|
fn right_assoc(
|
||||||
op: impl Parser<char, BinOp, Error = Error> + Clone + 'static,
|
op: impl Parser<char, BinOp, Error = Error> + 'static,
|
||||||
over: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
over: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> BoxedParser<'static, char, Expr, Error> {
|
) -> BoxedParser<'static, char, Expr, Error> {
|
||||||
let over_op = over
|
let over_op = over
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::builtin::Builtin;
|
||||||
|
|
||||||
use super::basic::{ident, space, Error};
|
use super::basic::{ident, space, Error};
|
||||||
|
|
||||||
fn builtin_lit() -> impl Parser<char, Builtin, Error = Error> + Clone {
|
fn builtin_lit() -> impl Parser<char, Builtin, Error = Error> {
|
||||||
just('\'').ignore_then(choice((
|
just('\'').ignore_then(choice((
|
||||||
text::keyword("get").to(Builtin::Get),
|
text::keyword("get").to(Builtin::Get),
|
||||||
text::keyword("set").to(Builtin::Set),
|
text::keyword("set").to(Builtin::Set),
|
||||||
|
|
@ -21,7 +21,7 @@ fn builtin_lit() -> impl Parser<char, Builtin, Error = Error> + Clone {
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn num_lit_str_radix(radix: u32) -> impl Parser<char, (i64, NumLitStr), Error = Error> + Clone {
|
fn num_lit_str_radix(radix: u32) -> impl Parser<char, (i64, NumLitStr), Error = Error> {
|
||||||
// Minimum amount of digits required to represent i64::MAX. The rest of this
|
// Minimum amount of digits required to represent i64::MAX. The rest of this
|
||||||
// code assumes that any value that can be represented using this amount of
|
// code assumes that any value that can be represented using this amount of
|
||||||
// digits fits into an u64.
|
// digits fits into an u64.
|
||||||
|
|
@ -71,14 +71,14 @@ fn num_lit_str_radix(radix: u32) -> impl Parser<char, (i64, NumLitStr), Error =
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn num_lit() -> impl Parser<char, NumLit, Error = Error> + Clone {
|
fn num_lit() -> impl Parser<char, NumLit, Error = Error> {
|
||||||
(just("0b").ignore_then(num_lit_str_radix(2)))
|
(just("0b").ignore_then(num_lit_str_radix(2)))
|
||||||
.or(just("0x").ignore_then(num_lit_str_radix(16)))
|
.or(just("0x").ignore_then(num_lit_str_radix(16)))
|
||||||
.or(num_lit_str_radix(10))
|
.or(num_lit_str_radix(10))
|
||||||
.map_with_span(|(value, str), span| NumLit { value, str, span })
|
.map_with_span(|(value, str), span| NumLit { value, str, span })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string_lit() -> impl Parser<char, StringLit, Error = Error> + Clone {
|
fn string_lit() -> impl Parser<char, StringLit, Error = Error> {
|
||||||
// TODO Parse string literals
|
// TODO Parse string literals
|
||||||
filter(|_| false).map(|_| unreachable!())
|
filter(|_| false).map(|_| unreachable!())
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +108,7 @@ pub fn table_lit_elem(
|
||||||
|
|
||||||
fn table_lit(
|
fn table_lit(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> impl Parser<char, TableLit, Error = Error> + Clone {
|
) -> impl Parser<char, TableLit, Error = Error> {
|
||||||
let elem = space()
|
let elem = space()
|
||||||
.then(table_lit_elem(expr))
|
.then(table_lit_elem(expr))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ impl Prefix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prefix_neg() -> impl Parser<char, Prefix, Error = Error> + Clone {
|
fn prefix_neg() -> impl Parser<char, Prefix, Error = Error> {
|
||||||
just('-')
|
just('-')
|
||||||
.map_with_span(|_, span| span)
|
.map_with_span(|_, span| span)
|
||||||
.then(space())
|
.then(space())
|
||||||
.map(|(minus, s0)| Prefix::Neg { minus, s0 })
|
.map(|(minus, s0)| Prefix::Neg { minus, s0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prefix_not() -> impl Parser<char, Prefix, Error = Error> + Clone {
|
fn prefix_not() -> impl Parser<char, Prefix, Error = Error> {
|
||||||
text::keyword("not")
|
text::keyword("not")
|
||||||
.map_with_span(|_, span| span)
|
.map_with_span(|_, span| span)
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -50,7 +50,7 @@ fn prefix_not() -> impl Parser<char, Prefix, Error = Error> + Clone {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefixed(
|
pub fn prefixed(
|
||||||
suffixed: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
suffixed: impl Parser<char, Expr, Error = Error> + 'static,
|
||||||
) -> BoxedParser<'static, char, Expr, Error> {
|
) -> BoxedParser<'static, char, Expr, Error> {
|
||||||
let prefix = prefix_neg()
|
let prefix = prefix_neg()
|
||||||
.or(prefix_not())
|
.or(prefix_not())
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,8 @@ impl Suffix {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suffix_call_arg(
|
fn suffix_call_arg(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error>,
|
||||||
) -> impl Parser<char, Suffix, Error = Error> + Clone {
|
) -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('('))
|
.then_ignore(just('('))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -147,7 +147,7 @@ fn suffix_call_arg(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suffix_call_no_arg() -> impl Parser<char, Suffix, Error = Error> + Clone {
|
fn suffix_call_no_arg() -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('('))
|
.then_ignore(just('('))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -157,15 +157,15 @@ fn suffix_call_no_arg() -> impl Parser<char, Suffix, Error = Error> + Clone {
|
||||||
|
|
||||||
fn suffix_call_constr(
|
fn suffix_call_constr(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> impl Parser<char, Suffix, Error = Error> + Clone {
|
) -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then(table_constr(expr))
|
.then(table_constr(expr))
|
||||||
.map(|(s0, constr)| Suffix::CallConstr { s0, constr })
|
.map(|(s0, constr)| Suffix::CallConstr { s0, constr })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suffix_field_access(
|
fn suffix_field_access(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error>,
|
||||||
) -> impl Parser<char, Suffix, Error = Error> + Clone {
|
) -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('['))
|
.then_ignore(just('['))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -182,7 +182,7 @@ fn suffix_field_access(
|
||||||
|
|
||||||
fn suffix_field_assign(
|
fn suffix_field_assign(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
||||||
) -> impl Parser<char, Suffix, Error = Error> + Clone {
|
) -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('['))
|
.then_ignore(just('['))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -206,7 +206,7 @@ fn suffix_field_assign(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suffix_field_access_ident() -> impl Parser<char, Suffix, Error = Error> + Clone {
|
fn suffix_field_access_ident() -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('.'))
|
.then_ignore(just('.'))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -215,8 +215,8 @@ fn suffix_field_access_ident() -> impl Parser<char, Suffix, Error = Error> + Clo
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suffix_field_assign_ident(
|
fn suffix_field_assign_ident(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error>,
|
||||||
) -> impl Parser<char, Suffix, Error = Error> + Clone {
|
) -> impl Parser<char, Suffix, Error = Error> {
|
||||||
space()
|
space()
|
||||||
.then_ignore(just('.'))
|
.then_ignore(just('.'))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -238,7 +238,7 @@ fn suffix_field_assign_ident(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffixed(
|
pub fn suffixed(
|
||||||
atom: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
atom: impl Parser<char, Expr, Error = Error> + 'static,
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> BoxedParser<'static, char, Expr, Error> {
|
) -> BoxedParser<'static, char, Expr, Error> {
|
||||||
let call_arg = suffix_call_arg(expr.clone());
|
let call_arg = suffix_call_arg(expr.clone());
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use super::lit::table_lit_elem;
|
||||||
|
|
||||||
fn table_constr_elem(
|
fn table_constr_elem(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
||||||
) -> impl Parser<char, TableConstrElem, Error = Error> + Clone {
|
) -> impl Parser<char, TableConstrElem, Error = Error> {
|
||||||
let lit = table_lit_elem(expr.clone()).map(TableConstrElem::Lit);
|
let lit = table_lit_elem(expr.clone()).map(TableConstrElem::Lit);
|
||||||
|
|
||||||
let indexed = just('[')
|
let indexed = just('[')
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::ast::{Expr, TableDestr, TablePattern, TablePatternElem};
|
||||||
|
|
||||||
use super::basic::{ident, space, Error};
|
use super::basic::{ident, space, Error};
|
||||||
|
|
||||||
fn table_pattern_elem() -> impl Parser<char, TablePatternElem, Error = Error> + Clone {
|
fn table_pattern_elem() -> impl Parser<char, TablePatternElem, Error = Error> {
|
||||||
let positional = ident().map(TablePatternElem::Positional);
|
let positional = ident().map(TablePatternElem::Positional);
|
||||||
|
|
||||||
let named = ident()
|
let named = ident()
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn table_pattern() -> BoxedParser<'static, char, TablePattern, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn table_destr(
|
pub fn table_destr(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone + 'static,
|
expr: impl Parser<char, Expr, Error = Error> + 'static,
|
||||||
) -> BoxedParser<'static, char, TableDestr, Error> {
|
) -> BoxedParser<'static, char, TableDestr, Error> {
|
||||||
let local = text::keyword("local").ignore_then(space()).or_not();
|
let local = text::keyword("local").ignore_then(space()).or_not();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ use crate::ast::{Expr, Var};
|
||||||
use super::basic::{ident, local, space, Error};
|
use super::basic::{ident, local, space, Error};
|
||||||
|
|
||||||
fn var_access(
|
fn var_access(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error>,
|
||||||
) -> impl Parser<char, Var, Error = Error> + Clone {
|
) -> impl Parser<char, Var, Error = Error> {
|
||||||
just('[')
|
just('[')
|
||||||
.ignore_then(space())
|
.ignore_then(space())
|
||||||
.then(expr)
|
.then(expr)
|
||||||
|
|
@ -24,7 +24,7 @@ fn var_access(
|
||||||
|
|
||||||
fn var_assign(
|
fn var_assign(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
||||||
) -> impl Parser<char, Var, Error = Error> + Clone {
|
) -> impl Parser<char, Var, Error = Error> {
|
||||||
local()
|
local()
|
||||||
.then_ignore(just('['))
|
.then_ignore(just('['))
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
@ -50,8 +50,8 @@ fn var_assign(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn var_assign_ident(
|
fn var_assign_ident(
|
||||||
expr: impl Parser<char, Expr, Error = Error> + Clone,
|
expr: impl Parser<char, Expr, Error = Error>,
|
||||||
) -> impl Parser<char, Var, Error = Error> + Clone {
|
) -> impl Parser<char, Var, Error = Error> {
|
||||||
local()
|
local()
|
||||||
.then(ident())
|
.then(ident())
|
||||||
.then(space())
|
.then(space())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue