File: copy.cc

package info (click to toggle)
flexc%2B%2B 2.17.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,180 kB
  • sloc: cpp: 6,467; makefile: 148; sh: 130; ansic: 18
file content (43 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download
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
// #define XERR
#include "fpattern.ih"

// Data:   fpattern: the initial fpattern
//         begin, end: the begin/end state indices of the initial fpattern
//         beginEnd: vector of pairs holding begin and end indices of copied
//                   fpatterns
//
//         lower and upper are the lower and upper limits of an Interval
// 
// First the initial number of required fpatterns is duplicated (the 1st one 
//         already being available as it is `fpattern' itself)
// 
// If the upper repetition limit is not set, make the last fpattern repeatable,
//         (and join the fpatterns) and leave.
// 
// Otherwise: dup the remaining fpatterns, allocating an extra state to allow 
//         for exits in between the fpattern boundaries. 
// 
// Once the remaining fpatterns are dupped, add their jumps to the end-state
// 
// Finally join all the fpatterns and return the begin-end states of the final
// (merged) fpattern.

FPattern FPattern::copy(States &states, 
                      FPattern &regex, size_t lower, size_t upper)
{
    PairVector beginEnd(1, Pair{regex.begin(), regex.end()});   
                                                        // begin/end indices
                                                        // of the regex

    copyFPattern(states, lower - 1, beginEnd);           // copy req'd fpatterns

    return
        upper == max<size_t>() ?    // no upper limit: 
            optRepeatLastFPattern(states,            // optionally  repeat the 
                            regex, lower, beginEnd) // last fpattern. 
        :                                       // Otherwise add fixed nr
            optionalFPatterns(states, regex,     // of optional fpatterns
                            lower, upper, beginEnd);
}