brzozowski_regex/builder/
pure.rs

1// Copyright 2024 Hendrik van Antwerpen
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::marker::PhantomData;
16
17use crate::builder::Builder;
18use crate::builder::Regex;
19use crate::Alphabet;
20
21/// A pure regular expression builder that keeps the structure of the constructor
22/// calls in the result.
23#[derive(Clone, Debug, Hash, PartialEq, Eq)]
24pub struct Pure<S: Alphabet> {
25    _phantom: PhantomData<S>,
26}
27
28impl<S: Alphabet> Builder for Pure<S> {
29    type Symbol = S;
30
31    #[inline]
32    fn empty_set() -> Regex<Self> {
33        Regex::EmptySet
34    }
35
36    #[inline]
37    fn empty_string() -> Regex<Self> {
38        Regex::EmptyString
39    }
40
41    #[inline]
42    fn symbol(value: S) -> Regex<Self> {
43        Regex::Symbol(value)
44    }
45
46    #[inline]
47    fn closure(inner: Regex<Self>) -> Regex<Self> {
48        Regex::Closure(inner.into())
49    }
50
51    #[inline]
52    fn concat(left: Regex<Self>, right: Regex<Self>) -> Regex<Self> {
53        Regex::Concat(left.into(), right.into())
54    }
55
56    #[inline]
57    fn or(left: Regex<Self>, right: Regex<Self>) -> Regex<Self> {
58        Regex::Or(left.into(), right.into())
59    }
60
61    #[inline]
62    fn and(left: Regex<Self>, right: Regex<Self>) -> Regex<Self> {
63        Regex::And(left.into(), right.into())
64    }
65
66    #[inline]
67    fn complement(inner: Regex<Self>) -> Regex<Self> {
68        Regex::Complement(inner.into())
69    }
70}