Skip to content

Commit 6c12469

Browse files
cenodisGeal
andauthored
Precedence parsing (#1362)
* Initial prototype * Update docs Remove unused code * More doc updates * Add feature flags for Vec * Add basic tests * Fix formatting * Add precedence to choosing_a_combinator.md * Fix typo * Minor refractoring * Update docs * Change parameter order * Add alloc feature to the entire precedence module The parser really cant work without it and the helpers dont make much sense without the parser. * Use fail parser to express "no operators of this type" * Document evaluation order * Better documentation for parameters * Fix precedence in documentation * Fix doc formatting * Fix typos * Use map_res when parsing integers * Example test for expressions with function calls and AST generation * Typo * Make evaluation a bit easier to read * Update expression_ast * Update expression_ast doc * Implement ternary operator in expression_ast * Shorten ast nodes * Implement some tests for parser failures * Update feature flags for docs * Properly append errors * Properly bubble up non Error errors * Split operators into 3 distinct types to help with exhaustiveness checks. --------- Co-authored-by: Geoffroy Couprie <contact@geoffroycouprie.com>
1 parent c8c0313 commit 6c12469

File tree

7 files changed

+622
-0
lines changed

7 files changed

+622
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ name = "css"
6666
[[test]]
6767
name = "custom_errors"
6868

69+
[[test]]
70+
name = "expression_ast"
71+
required-features = ["alloc"]
72+
6973
[[test]]
7074
name = "float"
7175

doc/choosing_a_combinator.md

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The following parsers could be found on [docs.rs number section](https://docs.rs
106106

107107
- [`escaped`](https://docs.rs/nom/latest/nom/bytes/complete/fn.escaped.html): Matches a byte string with escaped characters
108108
- [`escaped_transform`](https://docs.rs/nom/latest/nom/bytes/complete/fn.escaped_transform.html): Matches a byte string with escaped characters, and returns a new string with the escaped characters replaced
109+
- [`precedence`](https://docs.rs/nom/latest/nom/precedence/fn.precedence.html): Parses an expression with regards to operator precedence
109110

110111
## Binary format parsing
111112

src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ pub enum ErrorKind {
310310
Fail,
311311
Many,
312312
Fold,
313+
Precedence,
313314
}
314315

315316
#[rustfmt::skip]
@@ -373,6 +374,7 @@ pub fn error_to_u32(e: &ErrorKind) -> u32 {
373374
ErrorKind::Many => 76,
374375
ErrorKind::Fold => 77,
375376
ErrorKind::BinDigit => 78,
377+
ErrorKind::Precedence => 79,
376378
}
377379
}
378380

@@ -438,6 +440,7 @@ impl ErrorKind {
438440
ErrorKind::Fail => "Fail",
439441
ErrorKind::Many => "Many",
440442
ErrorKind::Fold => "Fold",
443+
ErrorKind::Precedence => "Precedence",
441444
}
442445
}
443446
}

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ pub mod bytes;
451451

452452
pub mod character;
453453

454+
pub mod precedence;
455+
454456
mod str;
455457

456458
pub mod number;

0 commit comments

Comments
 (0)