source: icGREP/icgrep-devel/icgrep/re/re_assertion.h

Last change on this file was 5493, checked in by cameron, 4 months ago

Restore check-ins from the last several days

File size: 2.5 KB
Line 
1/*
2 *  Copyright (c) 2015 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef RE_ASSERTION_H
8#define RE_ASSERTION_H
9
10#include <re/re_re.h>
11
12namespace re {
13
14class Assertion : public RE {
15public:
16    static inline bool classof(const RE * re) {
17        return re->getClassTypeId() == ClassTypeId::Assertion;
18    }
19    static inline bool classof(const void *) {
20        return false;
21    }
22    enum class Kind {Lookbehind, Lookahead, Boundary};
23    enum class Sense {Positive, Negative};
24
25    RE * getAsserted() const {return mAsserted;}
26    Assertion::Kind getKind() const {return mKind;}
27    Assertion::Sense getSense() const {return mSense;}
28    void setAsserted(RE * r) {mAsserted = r;}
29
30    static Assertion::Kind reverseKind(Assertion::Kind k);
31    static Assertion::Sense negateSense(Assertion::Sense s);
32
33protected:
34    friend Assertion * makeAssertion(RE * asserted, Kind k, Sense s);
35    Assertion(RE * r, Kind k, Sense s) : RE(ClassTypeId::Assertion), mAsserted(r), mKind(k), mSense(s) {}
36    virtual ~Assertion() {}
37
38private:
39    RE * mAsserted;
40    Kind mKind;
41    Sense mSense;
42};
43
44inline Assertion::Kind Assertion::reverseKind(Assertion::Kind k) {
45    if (k == Assertion::Kind::Boundary) return k;
46    return k == Assertion::Kind::Lookahead ? Assertion::Kind::Lookbehind : Assertion::Kind::Lookahead;
47}
48
49inline Assertion::Sense Assertion::negateSense(Assertion::Sense s) {
50    return s == Assertion::Sense::Positive ? Assertion::Sense::Negative : Assertion::Sense::Positive;
51}
52
53inline Assertion * makeAssertion(RE * asserted, Assertion::Kind k, Assertion::Sense s) {
54    return new Assertion(asserted, k, s);
55}
56
57inline RE * makeLookAheadAssertion(RE * r) {
58    return makeAssertion(r, Assertion::Kind::Lookahead, Assertion::Sense::Positive);
59}
60
61inline RE * makeNegativeLookAheadAssertion(RE * r) {
62    return makeAssertion(r, Assertion::Kind::Lookahead, Assertion::Sense::Negative);
63}
64
65inline RE * makeLookBehindAssertion(RE * r) {
66    return makeAssertion(r, Assertion::Kind::Lookbehind, Assertion::Sense::Positive);
67}
68
69inline RE * makeNegativeLookBehindAssertion(RE * r) {
70    return makeAssertion(r, Assertion::Kind::Lookbehind, Assertion::Sense::Negative);
71}
72
73inline RE * makeBoundaryAssertion(RE * r) {
74    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Positive);
75}
76
77inline RE * makeNegativeBoundaryAssertion(RE * r) {
78    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Negative);
79}
80   
81}
82
83#endif // RE_ASSERTION_H
84
Note: See TracBrowser for help on using the repository browser.