summaryrefslogtreecommitdiff
path: root/semiring/src/lib.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-02-27 12:36:41 +0800
committerJSDurand <mmemmew@gmail.com>2023-02-27 12:36:41 +0800
commitfbaa420ed550e9c3e7cdc09d4a8ec22bfbd782a6 (patch)
treefad9722825bb3fa796dd52c3fd4a8bf46b958cf9 /semiring/src/lib.rs
parentafad02bdff111ecccb0077b9c989e869723c231c (diff)
before a major refactor
I decide to adopt a new approach of recording and updating item derivation forests. Since this affects a lot of things, I decide to commit before the refactor, so that I can create a branch for that refactor.
Diffstat (limited to 'semiring/src/lib.rs')
-rw-r--r--semiring/src/lib.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/semiring/src/lib.rs b/semiring/src/lib.rs
index 9d096db..6c0e0d5 100644
--- a/semiring/src/lib.rs
+++ b/semiring/src/lib.rs
@@ -15,6 +15,8 @@
//! description. Specifically, it will produce items as it parses the
//! input string. Then we can execute these items by any interpreter.
+use grammar::Grammar;
+
/// A semiring is equipped with two operations: the addition and the
/// multiplication. It also has additive and multiplicative
/// identities. Also the two operations are supposed to be
@@ -29,14 +31,20 @@ pub trait Semiring {
fn one() -> Self;
/// The addition.
- fn add(&mut self, other: impl AsRef<Self>);
+ fn add(&mut self, other: &Self);
/// The multiplication.
- fn mul(&mut self, other: impl AsRef<Self>);
+ fn mul(&mut self, other: &Self);
+
+ /// A valuation associates a semiring value from a rule position.
+ ///
+ /// Since a position is not complete without a grammar, we also
+ /// give it a grammar.
+ fn valuation(pos: usize, grammar: &Grammar) -> Self;
}
-// TODO: Implement boolean semiring
-// TODO: Implement counting semiring
+pub mod counting;
+
// TODO: Implement derivation forest semiring
#[cfg(test)]