From e07510f05b08157c55f58e6f019609e4817f8a85 Mon Sep 17 00:00:00 2001 From: v-jkegler Date: Fri, 20 Sep 2024 16:16:47 -0400 Subject: [PATCH] Add comments to parser.rs (#15) Comment Scratch, ensure_items(), add_unique() --- parser/src/earley/parser.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser/src/earley/parser.rs b/parser/src/earley/parser.rs index c0d436db..80d12ffc 100644 --- a/parser/src/earley/parser.rs +++ b/parser/src/earley/parser.rs @@ -145,6 +145,7 @@ impl Item { } } +// This structure implements the Earley table. #[derive(Clone)] struct Scratch { grammar: Arc, @@ -256,6 +257,8 @@ impl Scratch { } } + // Make sure there is enough space in the Earley table, + // usually in preparation for adding Earley items. #[inline(always)] fn ensure_items(&mut self, n: usize) { if self.items.len() < n { @@ -320,6 +323,9 @@ impl Scratch { ); } + // Ensure that Earley table 'self' contains + // Earley item 'item'. That is, look for 'item' in 'self', + // and add 'item' to 'self' if it is not there already. #[inline(always)] fn add_unique(&mut self, item: Item, origin_item_idx: usize, info: &str) { if let Some(idx) = self.find_item(item) {