(syn: &Syntax, hasher: &mut blake3::Hasher)
| 685 | } |
| 686 | }, |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /// A Lean 4 concrete syntax tree node. |
| 691 | #[derive(Debug, PartialEq, Eq, Clone, Hash)] |
| 692 | pub enum Syntax { |
| 693 | /// Placeholder for missing syntax. |
| 694 | Missing, |
| 695 | /// An interior syntax node with a kind name and child nodes. |
| 696 | Node(SourceInfo, Name, Vec<Syntax>), |
| 697 | /// An atomic token (keyword, symbol, etc.). |
| 698 | Atom(SourceInfo, String), |
| 699 | /// An identifier with optional pre-resolved references. |
| 700 | Ident(SourceInfo, Substring, Name, Vec<SyntaxPreresolved>), |
| 701 | } |
| 702 | |
| 703 | fn hash_syntax(syn: &Syntax, hasher: &mut blake3::Hasher) { |
| 704 | hasher.update(&[MSYN]); |
| 705 | match syn { |
| 706 | Syntax::Missing => { |
| 707 | hasher.update(&[0]); |
| 708 | }, |
| 709 | Syntax::Node(info, kind, args) => { |
| 710 | hasher.update(&[1]); |
| 711 | hash_source_info(info, hasher); |
| 712 | hasher.update(kind.get_hash().as_bytes()); |
| 713 | hasher.update(&Nat::from(args.len() as u64).to_le_bytes()); |
| 714 | for arg in args { |
| 715 | hash_syntax(arg, hasher); |
| 716 | } |
| 717 | }, |
| 718 | Syntax::Atom(info, val) => { |
| 719 | hasher.update(&[2]); |
| 720 | hash_source_info(info, hasher); |
| 721 | hasher.update(val.as_bytes()); |
no test coverage detected