diff options
author | JSDurand <mmemmew@gmail.com> | 2022-12-23 00:36:31 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-12-23 00:36:31 +0800 |
commit | 8463dd24f815fe2b8f25fe9763e0a43023bfbb20 (patch) | |
tree | 343eea3c634efbbf72c64ed5dd778ecce60c3eea /nfa/src/desrec.rs | |
parent | 9f1c88b863e247da3cd60d2792a7a13b18e25e53 (diff) |
renaming core to chain and some other changes
Some changes:
- The core crate is renamed to "chain".
- The crate "viz" is added, which will provide layered graph drawing
algorithms.
- A function is added to convert from a grammar to the regular
language of its left-linear closures.
- A function is added to convert from a nondeterministic finite
automaton to its "null" closure. A null closure is the same
automaton with edges added, as if some edges are "null". Whether an
edge is null is determined by a function.
Combined with the previous change, we can convert a grammar to the
regular language of the null closure of its left-linear closures.
---
Now it remains to test more grammars and add an Atom trait, before
finishing the part about compilations.
Diffstat (limited to 'nfa/src/desrec.rs')
-rw-r--r-- | nfa/src/desrec.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/nfa/src/desrec.rs b/nfa/src/desrec.rs index c57d313..ac45c2d 100644 --- a/nfa/src/desrec.rs +++ b/nfa/src/desrec.rs @@ -20,8 +20,8 @@ pub trait DesRec { /// The type of errors encountered when parsing. type Error: std::error::Error; - /// Auxiliary data when parsing - type Aux; + /// Intermediate data when parsing + type Inter; /// The type of a scanner that classifies inputs into tokens. /// @@ -34,7 +34,14 @@ pub trait DesRec { /// /// - `Ok(Some(_))`: the classification succeeds and the parsing /// should continue. - type Scanner<'a>: FnMut(&'a str) -> Result<Option<(usize, Self::Label, Self::Aux)>, Self::Error>; + type Scanner<'a, 'b>: FnMut( + &'b Self, + &'a str, + ) + -> Result<Option<(usize, Self::Label, Self::Inter)>, Self::Error> + where + Self: 'b, + Self::Label: 'b; /// Parse a string into a regular expression with the aid of this /// type. @@ -42,9 +49,12 @@ pub trait DesRec { /// Accept a slice of string and return either a parsing error, or /// a pair of correctly parsed regular expression and the /// remaining slice. - fn parse<'a>( + fn parse<'a, 'b>( + &'b self, input: &'a str, - scanner: Self::Scanner<'a>, + scanner: Self::Scanner<'a, 'b>, post_p: bool, - ) -> Result<ParseOutput<'a, Self::Regex>, Self::Error>; + ) -> Result<ParseOutput<'a, Self::Regex>, Self::Error> + where + Self::Label: 'b; } |