Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/notation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ The following notations are used by the *Lexer* and *Syntax* grammar snippets:

Sequences have a higher precedence than `|` alternation.

r[notation.grammar.non-greedy]
### Non-greedy repetition

Repetition operators marked with "(non-greedy)" indicate that the repetition stops matching as soon as possible rather than matching as much as possible. For example:

```grammar,example
@root EXAMPLE_STRING ->
`"` ~`"`*? `"`
```

When presented with the input `"one" or "two"`, the EXAMPLE_STRING rule will match `"one"` instead of the entire input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that example isn't illustrating what you intend it to: with the ~" there, greediness doesn't make any difference. The repetition has to stop before the first " in any case.

r[notation.grammar.string-tables]
### String table productions

Expand Down
3 changes: 3 additions & 0 deletions tools/mdbook-spec/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ pub fn insert_summary(grammar: &Grammar, chapter: &Chapter, diag: &mut Diagnosti
.collect();
let mut grammar_summary = String::new();
for category in categories {
if category == "example" {
continue;
}
let mut chars = category.chars();
let cap = chars.next().unwrap().to_uppercase().collect::<String>() + chars.as_str();
write!(grammar_summary, "\n## {cap} summary\n\n").unwrap();
Expand Down