source: icGREP/icgrep-devel/icgrep/re_reducer.cpp @ 3935

Last change on this file since 3935 was 3935, checked in by daled, 5 years ago

The parser is now able to parse unicode categories.

File size: 2.0 KB
RevLine 
[3917]1#include "re_reducer.h"
2
3
4RE* RE_Reducer::reduce(RE* re, std::map<std::string, RE*>& re_map)
5{
6    RE* retVal = 0;
7
8    if (Alt* re_alt = dynamic_cast<Alt*>(re))
9    {
10        std::list<RE*> re_list;
11        std::list<RE*>::reverse_iterator rit = re_alt->GetREList()->rbegin();
12
13        for (rit = re_alt->GetREList()->rbegin(); rit != re_alt->GetREList()->rend(); ++rit)
14        {
15            re_list.push_back(reduce(*rit, re_map));
16        }
17
18        retVal = new Alt(&re_list);
19    }
20    else if (Seq* re_seq = dynamic_cast<Seq*>(re))
21    {
[3935]22/*
23        if (re_seq->getType() == Seq::Byte)
[3917]24        {
[3935]25            //If this is a sequence of byte classes then this is a multibyte sequence for a Unicode character class.
26            std::string seqname = re_seq->getName();
27            re_map.insert(make_pair(seqname, re_seq));
28            retVal = new Name(seqname);
[3917]29        }
[3935]30        else
31        {
32*/
33            std::list<RE*> re_list;
34            std::list<RE*>::iterator it;
[3917]35
[3935]36            for (it = re_seq->GetREList()->begin(); it != re_seq->GetREList()->end(); ++it)
37            {
38                re_list.push_front(reduce(*it, re_map));
39            }
40
41            retVal = new Seq(&re_list);
42//        }
[3917]43    }
44    else if (Rep* re_rep = dynamic_cast<Rep*>(re))
45    {
46        retVal = new Rep(reduce(re_rep->getRE(), re_map), re_rep->getLB(), re_rep->getUB());
47    }
48    else if (CC* re_cc = dynamic_cast<CC*>(re))
49    {
50        std::string ccname = re_cc->getName();
51        //If the character class isn't in the map then add it.
52        re_map.insert(make_pair(ccname, re_cc));
53        //return a new name class with the name of the character class.
54        retVal = new Name(ccname);
55    }
[3935]56    else if (Name* re_name = dynamic_cast<Name*>(re))
57    {
58        retVal = new Name(re_name->getName());
59    }
[3917]60    else if (Start* re_start = dynamic_cast<Start*>(re))
61    {
62        retVal = new Start();
63    }
64    else if (End* re_end = dynamic_cast<End*>(re))
65    {
66        retVal = new End();
67    }
68
69    return retVal;
70}
Note: See TracBrowser for help on using the repository browser.