Skip to content

Commit b7fd961

Browse files
authored
Merge pull request #154 from nikomatsakis/parser-cleanup
Parser cleanup
2 parents 2002ced + fab9e5f commit b7fd961

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
steps:
1717
- uses: actions/checkout@v2
18-
- name: Run cargo test
18+
- name: Run cargo test --all
1919
uses: actions-rs/cargo@v1
2020
with:
2121
command: test
2222
args: --all
23+
- name: Run cargo test --all-targets
24+
uses: actions-rs/cargo@v1
25+
with:
26+
command: test
27+
args: --all-targets
28+

book/src/formality_core/parse.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ When parsing an enum there will be multiple possibilities. We will attempt to pa
3131
We support left-recursive grammars like this one from the `parse-torture-tests`:
3232

3333
```rust
34-
{{#include ../../../tests/parser-torture-tests/src/path.rs:path}}
34+
{{#include ../../../tests/parser-torture-tests/path.rs:path}}
3535
```
3636

3737
We also support ambiguous grammars. For example, you can code up arithmetic expressions like this:
3838

3939

4040
```rust
41-
{{#include ../../../tests/parser-torture-tests/src/left_associative.rs:Expr}}
41+
{{#include ../../../tests/parser-torture-tests/left_associative.rs:Expr}}
4242
```
4343

4444
When specifying the `#[precedence]` of a variant, the default is left-associativity, which can be written more explicitly as `#[precedence(L, left)]`. If you prefer, you can specify right-associativity (`#[precedence(L, right)]`) or non-associativity `#[precedence(L, none)]`. This affects how things of the same level are parsed:
@@ -71,7 +71,7 @@ A grammar consists of a series of *symbols*. Each symbol matches some text in th
7171
* `$[?field]` -- parse `[E1, E2, E3]`, where `field: Vec<E>`, but accept empty string as empty vector
7272
* `${field}` -- parse `{E1, E2, E3}`, where `field: Vec<E>`
7373
* `${?field}` -- parse `{E1, E2, E3}`, where `field: Vec<E>`, but accept empty string as empty vector
74-
* `$:guard <nonterminal>` -- parses `<nonterminal>` but only if the keyword `guard` is present. For example, `$:where $,where_clauses` would parse `where WhereClause1, WhereClause2, WhereClause3`
74+
* `$:guard <nonterminal>` -- parses `<nonterminal>` but only if the keyword `guard` is present. For example, `$:where $,where_clauses` would parse `where WhereClause1, WhereClause2, WhereClause3` but would also accept nothing (in which case, you would get an empty vector).
7575

7676
### Greediness
7777

crates/formality-core/src/parse/parser/left_recursion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl StackEntry {
180180
}
181181
}
182182

183-
pub fn enter<'s, 't, L, T>(
183+
pub(super) fn enter<'s, 't, L, T>(
184184
scope: &'s Scope<L>,
185185
text: &'t str,
186186
mut op: impl FnMut(usize) -> ParseResult<'t, T>,
@@ -439,7 +439,7 @@ where
439439
}
440440
}
441441

442-
pub fn recurse<'s, 't, R>(current_state: CurrentState, op: impl FnOnce() -> R) -> R {
442+
pub(super) fn recurse<'s, 't, R>(current_state: CurrentState, op: impl FnOnce() -> R) -> R {
443443
STACK.with_borrow_mut(|stack| {
444444
let top = stack.last_mut().unwrap();
445445
assert!(

0 commit comments

Comments
 (0)