File: pattern.ih

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (130 lines) | stat: -rw-r--r-- 2,820 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "pattern"

/*
    The PerlSetFSA is a Finite State Automaton converting the special
character set characters as used by Perl to their corresponding
set-notations.

    The special perl-set characters may be used inside and outside of
character classes. When used in a class, it adds the set to the current
set. If the class starts with a caret, then the meaning of the set is
reversed:
            \s <-> \S
            \d <-> \D
(etc).

    The character sets s, d, and w are currently supported. \b and \B are
already part of the standard regex implementation.

*/

#include <iostream>
#include <vector>
#include <memory>

#include "../fswap/fswap"
#include "../ranger/ranger"


namespace FBB
{

class PerlSetFSA
{
    friend class Validator;

    enum State
    {
        Start,
        Bs,
        Set,
//        NegatedSet,
        SetBs,
//        NestedSet,
        InsideASet,
//        NegatedSetBs,
//        NegatedNestedSet,
//        InsideANegatedSet,

        nStates_
    };

    struct TransitionMatrix
    {
        State   d_state;
        int     d_input;
        State   d_next;
        void (PerlSetFSA::*d_action)();
    };

    static TransitionMatrix s_stateTransitions[];
    static TransitionMatrix *s_stateTransitions_end;

    class Validator
    {
        std::vector<bool> d_used;
        int     d_last;
        State   d_state;
        bool    d_valid;
        size_t d_element;

        public:
            Validator()
            :
                d_used(nStates_),
                d_last(0),
                d_state(nStates_),
                d_valid(true)
            {}
            void operator()(TransitionMatrix const &state);
            operator bool() const
            {
                return d_valid;
            }
    };

        // s_transition holds as many elements as there are states,
        // first: points to first element of corresponding state
        //          in s_transition
        // second: points just beyond the last element of corresponding
        //          state in s_transition

    using StatePair = std::pair<TransitionMatrix *, TransitionMatrix *>;

    static std::vector<StatePair> s_transition;

    std::string d_target;
    std::string::iterator d_next;

    public:
        //static void setup();
        PerlSetFSA();
        void convert(std::string &pattern);

    private:
        static void initialize(TransitionMatrix &stateDescription);

        void nop()
        {};
        void copy();
        void copybs();
        void w_Set();
        void W_Set();
        void d_Set();
        void D_Set();
        void s_Set();
        void S_Set();
        void w_Nest();
        void d_Nest();
        void s_Nest();
};

#include "destructor.f"
#include "newregex.f"

} // FBB


using namespace std;
using namespace FBB;