source: icGREP/icgrep-devel/icgrep/re/re_assertion.cpp @ 5896

Last change on this file since 5896 was 5896, checked in by cameron, 19 months ago

Start-of-text and End-of-text boundary assertions

File size: 1.4 KB
Line 
1/*
2 *  Copyright (c) 2017 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#include "re_assertion.h"
8#include "re_cc.h"
9#include "re_seq.h"
10#include "re_alt.h"
11#include "re_nullable.h"
12
13using namespace llvm;
14
15namespace re {
16   
17RE * makeSOT () {
18    return makeNegativeLookBehindAssertion(makeByte(0x00,0xFF));
19}
20
21RE * makeEOT () {
22    return makeNegativeLookAheadAssertion(makeByte(0x00,0xFF));
23}
24
25RE * expandBoundaryAssertion (RE * re) {
26    if (Assertion * a = dyn_cast<Assertion>(re)) {
27        if (a->getKind() == Assertion::Kind::Boundary) {
28            RE * asserted = a->getAsserted();
29            RE * behindP = makeAssertion(asserted, Assertion::Kind::Lookbehind, Assertion::Sense::Positive);
30            RE * behindN = makeAssertion(asserted, Assertion::Kind::Lookbehind, Assertion::Sense::Negative);
31            RE * aheadP = makeAssertion(asserted, Assertion::Kind::Lookahead, Assertion::Sense::Positive);
32            RE * aheadN = makeAssertion(asserted, Assertion::Kind::Lookahead, Assertion::Sense::Negative);
33            if (a->getSense() == Assertion::Sense::Positive) {
34                return makeAlt({makeSeq({behindP, aheadN}), makeSeq({behindN, aheadP})});
35            } else {
36                return makeAlt({makeSeq({behindP, aheadP}), makeSeq({behindN, aheadN})});
37            }
38        }
39    }
40    return re;
41}
42}
Note: See TracBrowser for help on using the repository browser.