Skip to content

Commit

Permalink
Replace ## with #{} in meta-grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Jan 19, 2025
1 parent 2873707 commit 51e4a3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
31 changes: 24 additions & 7 deletions peg-macros/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,11 @@ pub mod peg {
let mut __repeat_value = vec![];
loop {
let __pos = __repeat_pos;
let __step_res = __input.eat_until(__pos, ',');
let __step_res = ::peg::call_custom_closure(
(|input, pos| input.eat_until(pos, ',')),
__input,
__pos,
);
match __step_res {
::peg::RuleResult::Matched(__newpos, __value) => {
__repeat_pos = __newpos;
Expand Down Expand Up @@ -3639,7 +3643,7 @@ pub mod peg {
__pos: usize,
) -> ::peg::RuleResult<Span> {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
__input.next_span(__pos)
::peg::call_custom_closure((|input, pos| input.next_span(pos)), __input, __pos)
}
fn __parse_KEYWORD<'input>(
__input: &'input Input,
Expand Down Expand Up @@ -3755,7 +3759,8 @@ pub mod peg {
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let __seq_res = __input.ident(__pos);
let __seq_res =
::peg::call_custom_closure((|input, pos| input.ident(pos)), __input, __pos);
match __seq_res {
::peg::RuleResult::Matched(__pos, i) => {
::peg::RuleResult::Matched(__pos, (|| i)())
Expand All @@ -3774,7 +3779,7 @@ pub mod peg {
__pos: usize,
) -> ::peg::RuleResult<Literal> {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
__input.literal(__pos)
::peg::call_custom_closure((|input, pos| input.literal(pos)), __input, __pos)
}
fn __parse_PAREN_GROUP<'input>(
__input: &'input Input,
Expand All @@ -3783,7 +3788,11 @@ pub mod peg {
__pos: usize,
) -> ::peg::RuleResult<Group> {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
__input.group(__pos, Delimiter::Parenthesis)
::peg::call_custom_closure(
(|input, pos| input.group(pos, Delimiter::Parenthesis)),
__input,
__pos,
)
}
fn __parse_BRACE_GROUP<'input>(
__input: &'input Input,
Expand All @@ -3792,7 +3801,11 @@ pub mod peg {
__pos: usize,
) -> ::peg::RuleResult<Group> {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
__input.group(__pos, Delimiter::Brace)
::peg::call_custom_closure(
(|input, pos| input.group(pos, Delimiter::Brace)),
__input,
__pos,
)
}
fn __parse_BRACKET_GROUP<'input>(
__input: &'input Input,
Expand All @@ -3801,7 +3814,11 @@ pub mod peg {
__pos: usize,
) -> ::peg::RuleResult<Group> {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
__input.group(__pos, Delimiter::Bracket)
::peg::call_custom_closure(
(|input, pos| input.group(pos, Delimiter::Bracket)),
__input,
__pos,
)
}
fn __parse_LIFETIME<'input>(
__input: &'input Input,
Expand Down
14 changes: 7 additions & 7 deletions peg-macros/grammar.rustpeg
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ rule primary() -> SpannedExpr

rule rule_arg() -> RuleArg
= "<" e:expression() ">" { RuleArg::Peg(e) }
/ tt:$( ##eat_until(',')+ ) { RuleArg::Rust(tt) }
/ tt:$( #{|input, pos| input.eat_until(pos, ',')}+ ) { RuleArg::Rust(tt) }

rule precedence_level() -> PrecedenceLevel
= operators:precedence_op()+
Expand All @@ -154,13 +154,13 @@ rule precedence_op() -> PrecedenceOperator
= span:sp() elements:labeled()* action:BRACE_GROUP()
{ PrecedenceOperator{ span, elements, action } }

rule sp() -> Span = ##next_span()
rule sp() -> Span = #{|input, pos| input.next_span(pos)}
rule KEYWORD() = "pub" / "rule" / "use" / "type" / "where"
rule IDENT() -> Ident = !KEYWORD() i:##ident() {i}
rule LITERAL() -> Literal = ##literal()
rule PAREN_GROUP() -> Group = ##group(Delimiter::Parenthesis)
rule BRACE_GROUP() -> Group = ##group(Delimiter::Brace)
rule BRACKET_GROUP() -> Group = ##group(Delimiter::Bracket)
rule IDENT() -> Ident = !KEYWORD() i:#{|input, pos| input.ident(pos)} {i}
rule LITERAL() -> Literal = #{|input, pos| input.literal(pos)}
rule PAREN_GROUP() -> Group = #{|input, pos| input.group(pos, Delimiter::Parenthesis)}
rule BRACE_GROUP() -> Group = #{|input, pos| input.group(pos, Delimiter::Brace)}
rule BRACKET_GROUP() -> Group = #{|input, pos| input.group(pos, Delimiter::Bracket)}
rule LIFETIME() = "'" IDENT()
rule INTEGER() = LITERAL()

Expand Down

0 comments on commit 51e4a3a

Please sign in to comment.