bin_PROGRAMS = re2c
win_BINARIES = $(WINBUILDDIR)/re2c.exe
-re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc\
+re2c_SOURCES = code.cc dfa.cc main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
translate.cc scanner.cc mbo_getopt.cc print.cc \
enc.cc utf8.cc utf8_range.cc utf8_regexp.cc utf16.cc utf16_range.cc utf16_regexp.cc range_suffix.cc \
basics.h dfa.h globals.h ins.h parser.h re.h scanner.h \
;
}
-std::ostream& operator<<(std::ostream &o, const Range &r)
-{
- if ((r.ub - r.lb) == 1)
- {
- prtCh(o, r.lb);
- }
- else
- {
- prtCh(o, r.lb);
- o << "-";
- prtCh(o, r.ub - 1);
- }
-
- return o << r.next;
-}
-
-Range *doUnion(Range *r1, Range *r2)
-{
- Range *r, **rP = &r;
-
- for (;;)
- {
- Range *s;
-
- if (r1->lb <= r2->lb)
- {
- s = new Range(*r1);
- }
- else
- {
- s = new Range(*r2);
- }
-
- *rP = s;
- rP = &s->next;
-
- for (;;)
- {
- if (r1->lb <= r2->lb)
- {
- if (r1->lb > s->ub)
- break;
-
- if (r1->ub > s->ub)
- s->ub = r1->ub;
-
- if (!(r1 = r1->next))
- {
- uint ub = 0;
-
- for (; r2 && r2->lb <= s->ub; r2 = r2->next)
- ub = r2->ub;
-
- if (ub > s->ub)
- s->ub = ub;
-
- *rP = r2;
-
- return r;
- }
- }
- else
- {
- if (r2->lb > s->ub)
- break;
-
- if (r2->ub > s->ub)
- s->ub = r2->ub;
-
- if (!(r2 = r2->next))
- {
- uint ub = 0;
-
- for (; r1 && r1->lb <= s->ub; r1 = r1->next)
- ub = r1->ub;
-
- if (ub > s->ub)
- s->ub = ub;
-
- *rP = r1;
-
- return r;
- }
- }
- }
- }
-
- *rP = NULL;
- return r;
-}
-
-Range *doDiff(Range *r1, Range *r2)
-{
- Range *r, *s, **rP = &r;
-
- for (; r1; r1 = r1->next)
- {
- uint lb = r1->lb;
-
- for (; r2 && r2->ub <= r1->lb; r2 = r2->next)
-
- ;
- for (; r2 && r2->lb < r1->ub; r2 = r2->next)
- {
- if (lb < r2->lb)
- {
- *rP = s = new Range(lb, r2->lb);
- rP = &s->next;
- }
-
- if ((lb = r2->ub) >= r1->ub)
- goto noMore;
- }
-
- *rP = s = new Range(lb, r1->ub);
- rP = &s->next;
-
-noMore:
- ;
- }
-
- *rP = NULL;
- return r;
-}
-
MatchOp *merge(MatchOp *m1, MatchOp *m2)
{
if (!m1)
--- /dev/null
+#include "print.h"
+#include "range.h"
+
+namespace re2c
+{
+
+std::ostream& operator<<(std::ostream &o, const Range &r)
+{
+ if ((r.ub - r.lb) == 1)
+ {
+ prtCh(o, r.lb);
+ }
+ else
+ {
+ prtCh(o, r.lb);
+ o << "-";
+ prtCh(o, r.ub - 1);
+ }
+
+ return o << r.next;
+}
+
+Range *doUnion(Range *r1, Range *r2)
+{
+ if (r1 == NULL)
+ return r2;
+ if (r2 == NULL)
+ return r1;
+
+ Range *r, **rP = &r;
+
+ for (;;)
+ {
+ Range *s;
+
+ if (r1->lb <= r2->lb)
+ {
+ s = new Range(*r1);
+ }
+ else
+ {
+ s = new Range(*r2);
+ }
+
+ *rP = s;
+ rP = &s->next;
+
+ for (;;)
+ {
+ if (r1->lb <= r2->lb)
+ {
+ if (r1->lb > s->ub)
+ break;
+
+ if (r1->ub > s->ub)
+ s->ub = r1->ub;
+
+ if (!(r1 = r1->next))
+ {
+ uint ub = 0;
+
+ for (; r2 && r2->lb <= s->ub; r2 = r2->next)
+ ub = r2->ub;
+
+ if (ub > s->ub)
+ s->ub = ub;
+
+ *rP = r2;
+
+ return r;
+ }
+ }
+ else
+ {
+ if (r2->lb > s->ub)
+ break;
+
+ if (r2->ub > s->ub)
+ s->ub = r2->ub;
+
+ if (!(r2 = r2->next))
+ {
+ uint ub = 0;
+
+ for (; r1 && r1->lb <= s->ub; r1 = r1->next)
+ ub = r1->ub;
+
+ if (ub > s->ub)
+ s->ub = ub;
+
+ *rP = r1;
+
+ return r;
+ }
+ }
+ }
+ }
+
+ *rP = NULL;
+ return r;
+}
+
+Range *doDiff(Range *r1, Range *r2)
+{
+ Range *r, *s, **rP = &r;
+
+ for (; r1; r1 = r1->next)
+ {
+ uint lb = r1->lb;
+
+ for (; r2 && r2->ub <= r1->lb; r2 = r2->next)
+
+ ;
+ for (; r2 && r2->lb < r1->ub; r2 = r2->next)
+ {
+ if (lb < r2->lb)
+ {
+ *rP = s = new Range(lb, r2->lb);
+ rP = &s->next;
+ }
+
+ if ((lb = r2->ub) >= r1->ub)
+ goto noMore;
+ }
+
+ *rP = s = new Range(lb, r1->ub);
+ rP = &s->next;
+
+noMore:
+ ;
+ }
+
+ *rP = NULL;
+ return r;
+}
+
+} // end namespace re2c
--- /dev/null
+#ifndef _range_h
+#define _range_h
+
+#include <iostream>
+
+#include "basics.h"
+#include "free_list.h"
+
+namespace re2c
+{
+
+class Range
+{
+
+public:
+ Range *next;
+ uint lb, ub; // [lb,ub)
+
+ static free_list<Range*> vFreeList;
+
+public:
+ Range(uint l, uint u) : next(NULL), lb(l), ub(u)
+ {
+ vFreeList.insert(this);
+ }
+
+ Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub)
+ {
+ vFreeList.insert(this);
+ }
+
+ ~Range()
+ {
+ vFreeList.erase(this);
+ }
+
+ friend std::ostream& operator<<(std::ostream&, const Range&);
+ friend std::ostream& operator<<(std::ostream&, const Range*);
+};
+
+inline std::ostream& operator<<(std::ostream &o, const Range *r)
+{
+ return r ? o << *r : o;
+}
+
+Range *doUnion(Range *r1, Range *r2);
+Range *doDiff(Range *r1, Range *r2);
+
+} // end namespace re2c
+
+#endif
#include "ins.h"
#include "free_list.h"
#include "globals.h"
+#include "range.h"
#include "smart_ptr.h"
namespace re2c
CharPtn *ptn;
};
-class Range
-{
-
-public:
- Range *next;
- uint lb, ub; // [lb,ub)
-
- static free_list<Range*> vFreeList;
-
-public:
- Range(uint l, uint u) : next(NULL), lb(l), ub(u)
- {
- vFreeList.insert(this);
- }
-
- Range(Range &r) : next(NULL), lb(r.lb), ub(r.ub)
- {
- vFreeList.insert(this);
- }
-
- ~Range()
- {
- vFreeList.erase(this);
- }
-
- friend std::ostream& operator<<(std::ostream&, const Range&);
- friend std::ostream& operator<<(std::ostream&, const Range*);
-};
-
-inline std::ostream& operator<<(std::ostream &o, const Range *r)
-{
- return r ? o << *r : o;
-}
-
class RegExp
{