Skip to content

Commit

Permalink
Remove support for crate visibility modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Oct 11, 2023
1 parent 400acf6 commit d51f5c4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 109 deletions.
63 changes: 33 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions benches/expr.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![feature(test, crate_visibility_modifier)]
#![feature(test)]
extern crate peg;

extern crate test;

use test::Bencher;

peg::parser!(grammar parser() for str {
crate rule expr() = eq()
pub(crate) rule expr() = eq()

#[cache]
rule eq() = additive() "=" eq() / additive()
Expand Down
104 changes: 31 additions & 73 deletions peg-macros/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,54 +970,31 @@ pub mod peg {
#![allow(non_snake_case, unused, clippy::redundant_closure_call)]
match {
let str_start = __pos;
match {
let __choice_res =
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "pub") {
::peg::RuleResult::Matched(__pos, __val) => {
let __seq_res = match match __parse_PAREN_GROUP(
__input,
__state,
__err_state,
__pos,
) {
::peg::RuleResult::Matched(pos, _) => {
::peg::RuleResult::Matched(pos, ())
}
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
} {
::peg::RuleResult::Matched(__newpos, _) => {
::peg::RuleResult::Matched(__newpos, ())
}
::peg::RuleResult::Failed => ::peg::RuleResult::Matched(__pos, ()),
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
::peg::RuleResult::Matched(__pos, ())
}
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
}
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"pub\"");
::peg::RuleResult::Failed
}
};
match __choice_res {
::peg::RuleResult::Matched(__pos, __value) => {
::peg::RuleResult::Matched(__pos, __value)
}
::peg::RuleResult::Failed => {
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "crate") {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
match match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "pub") {
::peg::RuleResult::Matched(__pos, __val) => {
let __seq_res =
match match __parse_PAREN_GROUP(__input, __state, __err_state, __pos) {
::peg::RuleResult::Matched(pos, _) => {
::peg::RuleResult::Matched(pos, ())
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"crate\"");
::peg::RuleResult::Failed
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
} {
::peg::RuleResult::Matched(__newpos, _) => {
::peg::RuleResult::Matched(__newpos, ())
}
::peg::RuleResult::Failed => ::peg::RuleResult::Matched(__pos, ()),
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
::peg::RuleResult::Matched(__pos, ())
}
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
}
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"pub\"");
::peg::RuleResult::Failed
}
} {
::peg::RuleResult::Matched(__newpos, _) => ::peg::RuleResult::Matched(
__newpos,
Expand Down Expand Up @@ -3172,12 +3149,12 @@ pub mod peg {
}
::peg::RuleResult::Failed => {
let __choice_res =
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "crate") {
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "rule") {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"crate\"");
__err_state.mark_failure(__pos, "\"rule\"");
::peg::RuleResult::Failed
}
};
Expand All @@ -3187,13 +3164,13 @@ pub mod peg {
}
::peg::RuleResult::Failed => {
let __choice_res = match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "rule",
__input, __pos, "use",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"rule\"");
__err_state.mark_failure(__pos, "\"use\"");
::peg::RuleResult::Failed
}
};
Expand All @@ -3202,34 +3179,15 @@ pub mod peg {
::peg::RuleResult::Matched(__pos, __value)
}
::peg::RuleResult::Failed => {
let __choice_res =
match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "use",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"use\"");
::peg::RuleResult::Failed
}
};
match __choice_res {
::peg::RuleResult::Matched(__pos, __value) => {
::peg::RuleResult::Matched(__pos, __value)
match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "type",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "type",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"type\"");
::peg::RuleResult::Failed
}
}
__err_state.mark_failure(__pos, "\"type\"");
::peg::RuleResult::Failed
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions peg-macros/grammar.rustpeg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rule item() -> Item

rule rust_doc_comment() -> Option<TokenStream> = $(("#" "[" "doc" "=" LITERAL() "]")*)?

rule rust_visibility() -> Option<TokenStream> = $("pub" PAREN_GROUP()? / "crate")?
rule rust_visibility() -> Option<TokenStream> = $("pub" PAREN_GROUP()?)?

rule rust_use() -> TokenStream
= v:$("use" rust_path() (
Expand Down Expand Up @@ -147,7 +147,7 @@ rule precedence_op() -> PrecedenceOperator
{ PrecedenceOperator{ span, elements, action } }

rule sp() -> Span = ##next_span()
rule KEYWORD() = "pub" / "crate" / "rule" / "use" / "type"
rule KEYWORD() = "pub" / "rule" / "use" / "type"
rule IDENT() -> Ident = !KEYWORD() i:##ident() {i}
rule LITERAL() -> Literal = ##literal()
rule PAREN_GROUP() -> Group = ##group(Delimiter::Parenthesis)
Expand Down
4 changes: 2 additions & 2 deletions tests/compile-fail/syntax_error.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected one of "#", "crate", "pub", "rule", "use", "}"
--> $DIR/syntax_error.rs:4:5
error: expected one of "#", "pub", "rule", "use", "}"
--> tests/compile-fail/syntax_error.rs:4:5
|
4 | fn asdf() {} //~ ERROR expected one of "#", "crate", "pub", "rule", "use", "}"
| ^^

0 comments on commit d51f5c4

Please sign in to comment.