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

Last change on this file since 5810 was 5725, checked in by cameron, 16 months ago

Utility functions for regular expression transformations

File size: 1.2 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_seq.h"
9#include "re_alt.h"
10#include "re_nullable.h"
11
12using namespace llvm;
13
14namespace re {
15
16RE * expandBoundaryAssertion (RE * re) {
17    if (Assertion * a = dyn_cast<Assertion>(re)) {
18        if (a->getKind() == Assertion::Kind::Boundary) {
19            RE * asserted = a->getAsserted();
20            RE * behindP = makeAssertion(asserted, Assertion::Kind::Lookbehind, Assertion::Sense::Positive);
21            RE * behindN = makeAssertion(asserted, Assertion::Kind::Lookbehind, Assertion::Sense::Negative);
22            RE * aheadP = makeAssertion(asserted, Assertion::Kind::Lookahead, Assertion::Sense::Positive);
23            RE * aheadN = makeAssertion(asserted, Assertion::Kind::Lookahead, Assertion::Sense::Negative);
24            if (a->getSense() == Assertion::Sense::Positive) {
25                return makeAlt({makeSeq({behindP, aheadN}), makeSeq({behindN, aheadP})});
26            } else {
27                return makeAlt({makeSeq({behindP, aheadP}), makeSeq({behindN, aheadN})});
28            }
29        }
30    }
31    return re;
32}
33}
Note: See TracBrowser for help on using the repository browser.