src/ir/regexp/regexp_match.h \
src/ir/regexp/regexp_rule.h \
src/ir/regexp/regexp_cat.h \
- src/ir/regexp/regexp_closev.h \
src/ir/regexp/regexp_null.h \
src/ir/regexp/regexp.h \
src/ir/regexp/regexp_close.h \
#include "src/ir/regexp/regexp_alt.h"
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
-#include "src/ir/regexp/regexp_closev.h"
#include "src/ir/regexp/regexp_match.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/ir/regexp/regexp_rule.h"
size = exp->size + 1;
}
-void CloseVOp::calcSize (Char * rep)
-{
- exp->calcSize (rep);
- if (max >= 0)
- {
- size = (exp->size * min) + ((1 + exp->size) * (max - min));
- }
- else
- {
- size = (exp->size * min) + 1;
- }
-}
-
void MatchOp::calcSize (Char * rep)
{
size = 1;
#include "src/ir/regexp/regexp_alt.h"
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
-#include "src/ir/regexp/regexp_closev.h"
#include "src/ir/regexp/regexp_match.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/ir/regexp/regexp_rule.h"
}
}
-uint32_t CloseVOp::compile (Char * rep, Ins * i)
-{
- if (ins_cache)
- {
- return compile_goto (ins_cache, i);
- }
- else
- {
- ins_cache = i;
-
- for (int st = min; st < max; st++)
- {
- const uint32_t sz = exp->compile (rep, &i[1]);
- i->i.tag = FORK;
- i->i.link = ins_cache + (1 + sz) * (max - min);
- i += sz + 1;
- }
- for (int st = 0; st < min; st++)
- {
- const uint32_t sz = exp->compile (rep, &i[0]);
- i += sz;
- if (max < 0 && st == 0)
- {
- i->i.tag = FORK;
- i->i.link = i - sz;
- i++;
- }
- }
- const uint32_t sz = static_cast<uint32_t> (i - ins_cache);
-
- if (ins_access == PRIVATE)
- {
- decompile ();
- }
-
- return sz;
- }
-}
-
-void CloseVOp::decompile ()
-{
- if (ins_cache)
- {
- exp->decompile ();
- ins_cache = NULL;
- }
-}
-
uint32_t MatchOp::compile (Char * rep, Ins * i)
{
if (ins_cache)
#include "src/ir/regexp/regexp_alt.h"
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
-#include "src/ir/regexp/regexp_closev.h"
#include "src/ir/regexp/regexp_match.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/ir/regexp/regexp_rule.h"
exp->split (s);
}
-void CloseVOp::split (CharSet & s)
-{
- exp->split (s);
-}
-
void MatchOp::split (CharSet & s)
{
for (Range *r = match; r; r = r->next ())
#include "src/ir/regexp/regexp_alt.h"
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
-#include "src/ir/regexp/regexp_closev.h"
#include "src/ir/regexp/regexp_match.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/ir/regexp/regexp_rule.h"
o << exp << "+";
}
-void CloseVOp::display (std::ostream & o) const
-{
- o << exp << "+";
-}
-
void MatchOp::display (std::ostream & o) const
{
o << match;
#include "src/ir/regexp/regexp.h"
#include "src/ir/regexp/regexp_alt.h"
#include "src/ir/regexp/regexp_cat.h"
+#include "src/ir/regexp/regexp_close.h"
#include "src/ir/regexp/regexp_match.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/parse/scanner.h"
return new MatchOp(def);
}
+/*
+ * note [counted repetition expansion]
+ *
+ * r{0} ;;= <empty regexp>
+ * r{n} ::= r{n-1} r
+ * r{n,m} ::= r{n} (r{0} | ... | r{m-n})
+ * r{n,} ::= r{n} r*
+ */
+
+// see note [counted repetition expansion]
+RegExp * repeat (RegExp * e, uint32_t n)
+{
+ RegExp * r = NULL;
+ for (uint32_t i = 0; i < n; ++i)
+ {
+ r = doCat (r, e);
+ }
+ return r;
+}
+
+// see note [counted repetition expansion]
+RegExp * repeat_from_to (RegExp * e, uint32_t n, uint32_t m)
+{
+ RegExp * r1 = repeat (e, n);
+ RegExp * r2 = NULL;
+ for (uint32_t i = n; i < m; ++i)
+ {
+ r2 = mkAlt (new NullOp, doCat (e, r2));
+ }
+ return doCat (r1, r2);
+}
+
+// see note [counted repetition expansion]
+RegExp * repeat_from (RegExp * e, uint32_t n)
+{
+ RegExp * r1 = repeat (e, n);
+ RegExp * r2 = mkAlt (new NullOp, new CloseOp (e));
+ return doCat (r1, r2);
+}
+
} // namespace re2c
RegExp * doAlt (RegExp * e1, RegExp * e2);
RegExp * mkAlt (RegExp * e1, RegExp * e2);
RegExp * doCat (RegExp * e1, RegExp * e2);
+RegExp * repeat (RegExp * e, uint32_t n);
+RegExp * repeat_from_to (RegExp * e, uint32_t n, uint32_t m);
+RegExp * repeat_from (RegExp * e, uint32_t n);
} // end namespace re2c
+++ /dev/null
-#ifndef _RE2C_IR_REGEXP_REGEXP_CLOSEV_
-#define _RE2C_IR_REGEXP_REGEXP_CLOSEV_
-
-#include "src/ir/regexp/regexp.h"
-
-namespace re2c
-{
-
-class CloseVOp: public RegExp
-{
- RegExp * exp;
- int32_t min;
- int32_t max;
-
-public:
- inline CloseVOp (RegExp * e, int lb, int ub)
- : exp (e)
- , min (lb)
- , max (ub)
- {
- exp->ins_access = PRIVATE;
- }
- void split (CharSet &);
- void calcSize (Char *);
- uint32_t compile (Char *, Ins *);
- void decompile ();
- void display (std::ostream & o) const;
-
- FORBID_COPY (CloseVOp);
-};
-
-} // end namespace re2c
-
-#endif // _RE2C_IR_REGEXP_REGEXP_CLOSEV_
#include "src/ir/regexp/encoding/range_suffix.h"
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
-#include "src/ir/regexp/regexp_closev.h"
#include "src/ir/regexp/regexp_null.h"
#include "src/codegen/emit.h" // genTypes
#include "src/globals.h"
}
| primary CLOSESIZE
{
- $$ = new CloseVOp($1, $2.minsize, $2.maxsize);
+ $1->ins_access = RegExp::PRIVATE;
+ if ($2.maxsize < 0)
+ {
+ $$ = repeat_from ($1, $2.minsize);
+ }
+ else if ($2.minsize == $2.maxsize)
+ {
+ $$ = repeat ($1, $2.minsize);
+ }
+ else
+ {
+ $$ = repeat_from_to ($1, $2.minsize, $2.maxsize);
+ }
+ $$ = $$ ? $$ : new NullOp;
}
;