Skip to content

Commit

Permalink
Merge pull request #232 from dario23/allow-multiline-doc-comments
Browse files Browse the repository at this point in the history
Allow multiline doc-comments
  • Loading branch information
kevinmehall authored Jun 13, 2020
2 parents 8898f64 + 1397816 commit 6dc3033
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
93 changes: 61 additions & 32 deletions peg-macros/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,74 +826,95 @@ pub mod peg {
match {
let str_start = __pos;
match {
let __seq_res = match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "#")
{
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => __err_state.mark_failure(__pos, "\"#\""),
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let mut __repeat_pos = __pos;
loop {
let __pos = __repeat_pos;
let __step_res = {
let __seq_res =
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "[") {
match ::peg::ParseLiteral::parse_string_literal(__input, __pos, "#") {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"[\"")
__err_state.mark_failure(__pos, "\"#\"")
}
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let __seq_res = match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "doc",
__input, __pos, "[",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"doc\"")
__err_state.mark_failure(__pos, "\"[\"")
}
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let __seq_res =
match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "=",
__input, __pos, "doc",
) {
::peg::RuleResult::Matched(__pos, __val) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"=\"")
__err_state.mark_failure(__pos, "\"doc\"")
}
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let __seq_res = match __parse_LITERAL(
__input,
__state,
__err_state,
__pos,
) {
::peg::RuleResult::Matched(pos, _) => {
::peg::RuleResult::Matched(pos, ())
}
::peg::RuleResult::Failed => {
::peg::RuleResult::Failed
}
};
let __seq_res =
match ::peg::ParseLiteral::parse_string_literal(
__input, __pos, "=",
) {
::peg::RuleResult::Matched(
__pos,
__val,
) => {
::peg::RuleResult::Matched(__pos, __val)
}
::peg::RuleResult::Failed => {
__err_state.mark_failure(__pos, "\"=\"")
}
};
match __seq_res {
::peg::RuleResult::Matched(__pos, _) => {
let __seq_res = match :: peg :: ParseLiteral :: parse_string_literal ( __input , __pos , "]" ) { :: peg :: RuleResult :: Matched ( __pos , __val ) => :: peg :: RuleResult :: Matched ( __pos , __val ) , :: peg :: RuleResult :: Failed => __err_state . mark_failure ( __pos , "\"]\"" ) } ;
let __seq_res = match __parse_LITERAL(
__input,
__state,
__err_state,
__pos,
) {
::peg::RuleResult::Matched(pos, _) => {
::peg::RuleResult::Matched(pos, ())
}
::peg::RuleResult::Failed => {
::peg::RuleResult::Failed
}
};
match __seq_res {
::peg::RuleResult::Matched(
__pos,
_,
) => {
::peg::RuleResult::Matched(__pos, {
})
let __seq_res = match :: peg :: ParseLiteral :: parse_string_literal ( __input , __pos , "]" ) { :: peg :: RuleResult :: Matched ( __pos , __val ) => :: peg :: RuleResult :: Matched ( __pos , __val ) , :: peg :: RuleResult :: Failed => __err_state . mark_failure ( __pos , "\"]\"" ) } ;
match __seq_res {
::peg::RuleResult::Matched(
__pos,
_,
) => {
::peg::RuleResult::Matched(
__pos,
{},
)
}
::peg::RuleResult::Failed => {
::peg::RuleResult::Failed
}
}
}
::peg::RuleResult::Failed => {
::peg::RuleResult::Failed
Expand All @@ -913,9 +934,17 @@ pub mod peg {
}
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
}
};
match __step_res {
::peg::RuleResult::Matched(__newpos, __value) => {
__repeat_pos = __newpos;
}
::peg::RuleResult::Failed => {
break;
}
}
::peg::RuleResult::Failed => ::peg::RuleResult::Failed,
}
::peg::RuleResult::Matched(__repeat_pos, ())
} {
::peg::RuleResult::Matched(__newpos, _) => ::peg::RuleResult::Matched(
__newpos,
Expand Down
2 changes: 1 addition & 1 deletion peg-macros/grammar.rustpeg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rule item() -> Item
= u:rust_use() { Item::Use(u) }
/ r:peg_rule() { Item::Rule(r) }

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/arithmetic_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parser!{
/// Doc comment
grammar arithmetic() for str {
/// Top level parser rule
/// This doc comment has multiple lines to test support for that as well
pub rule expression() -> Expression
= sum()

Expand Down

0 comments on commit 6dc3033

Please sign in to comment.