src/tcmd.h \
src/skeleton/path.h \
src/skeleton/skeleton.h \
+ src/ast/ast.h \
src/ast/extop.h \
src/ast/input.h \
src/ast/parser.h \
- src/ast/regexp.h \
src/ast/rules.h \
src/ast/scanner.h \
src/ast/unescape.h \
src/tag.cc \
src/tcmd.cc \
src/main.cc \
+ src/ast/ast.cc \
src/ast/input.cc \
- src/ast/regexp.cc \
src/ast/scanner.cc \
src/ast/unescape.cc \
src/util/s_to_n32_unsafe.cc \
-/* Generated by re2c 0.16 on Sun Mar 5 10:37:44 2017 */
+/* Generated by re2c 0.16 on Sun Mar 5 11:37:40 2017 */
#line 1 "../src/ast/lex.re"
#include "src/util/c99_stdint.h"
#include <stddef.h>
#include "src/re/encoding/enc.h"
#include "src/ast/extop.h"
#include "src/ast/input.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/ast/scanner.h"
#include "src/ast/parser.h" // needed by "y.tab.h"
#include "src/ast/unescape.h"
++YYCURSOR;
#line 358 "../src/ast/lex.re"
{
- yylval.regexp = RegExp::make_dot(cline, get_column());
+ yylval.regexp = ast_dot(cline, get_column());
return TOKEN_REGEXP;
}
#line 1057 "src/ast/lex.cc"
yylval.str = new std::string (tok, tok_len());
return TOKEN_ID;
} else {
- const RegExp *r = NULL;
+ const AST *r = NULL;
const bool casing = opts->bCaseInsensitive || opts->bCaseInverted;
for (char *s = tok; s < cur; ++s) {
const uint32_t
c = static_cast<uint8_t>(*s),
column = static_cast<uint32_t>(s - pos);
- r = RegExp::make_cat(r, casing
- ? RegExp::make_ichar(cline, column, c)
- : RegExp::make_schar(cline, column, c));
+ r = ast_cat(r, casing
+ ? ast_ichar(cline, column, c)
+ : ast_schar(cline, column, c));
}
- yylval.regexp = r ? r : RegExp::make_nil(cline, get_column());
+ yylval.regexp = r ? r : ast_nil(cline, get_column());
return TOKEN_REGEXP;
}
}
fatal("tags are only allowed with '-T, --tags' option");
}
const std::string *name = new std::string(tok + 1, tok_len() - 1);
- yylval.regexp = RegExp::make_tag(cline, get_column(), name);
+ yylval.regexp = ast_tag(cline, get_column(), name);
return TOKEN_REGEXP;
}
#line 1291 "src/ast/lex.cc"
}
}
-const RegExp *Scanner::lex_cls(bool neg)
+const AST *Scanner::lex_cls(bool neg)
{
const uint32_t column = get_column();
Range *r = NULL, *s;
if (neg) {
r = Range::sub(opts->encoding.fullRange(), r);
}
- return RegExp::make_class(cline, column, r);
+ return ast_class(cline, column, r);
}
uint32_t Scanner::lex_cls_chr()
}
-const RegExp *Scanner::lex_str(char quote, bool casing)
+const AST *Scanner::lex_str(char quote, bool casing)
{
- const RegExp *r = NULL;
+ const AST *r = NULL;
for (bool end;;) {
const uint32_t c = lex_str_chr(quote, end);
if (end) {
- return r ? r : RegExp::make_nil(cline, get_column());
+ return r ? r : ast_nil(cline, get_column());
}
- r = RegExp::make_cat(r, casing
- ? RegExp::make_ichar(cline, get_column(), c)
- : RegExp::make_schar(cline, get_column(), c));
+ r = ast_cat(r, casing
+ ? ast_ichar(cline, get_column(), c)
+ : ast_schar(cline, get_column(), c));
}
}
#include "src/skeleton/skeleton.h"
#include "src/ast/extop.h"
#include "src/ast/parser.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/ast/scanner.h"
#include "src/util/free_list.h"
#include "src/util/range.h"
for (i = b; i != e; ++i) {
if (!i->defs.empty()) {
const Code *c = i->defs[0];
- const RegExp *r = RegExp::make_default(c->fline, 0);
- i->rules.push_back(RegExpRule(r, c));
+ const AST *r = ast_default(c->fline, 0);
+ i->rules.push_back(ASTRule(r, c));
}
}
{
- const re2c::RegExp * regexp;
+ const re2c::AST * regexp;
re2c::Code * code;
char op;
re2c::ExtOp extop;
case 12:
{
- find(context.specs, "").rules.push_back(RegExpRule((yyvsp[-1].regexp), (yyvsp[0].code)));
+ find(context.specs, "").rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
}
break;
{
for(CondList::const_iterator i = (yyvsp[-3].clist)->begin(); i != (yyvsp[-3].clist)->end(); ++i) {
- find(context.specs, *i).rules.push_back(RegExpRule((yyvsp[-1].regexp), (yyvsp[0].code)));
+ find(context.specs, *i).rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
}
delete (yyvsp[-3].clist);
}
case 17:
{
- const RegExp *r = RegExp::make_nil(context.input.get_cline(), 0);
- find(context.specs, "0").rules.push_back(RegExpRule(r, (yyvsp[0].code)));
+ const AST *r = ast_nil(context.input.get_cline(), 0);
+ find(context.specs, "0").rules.push_back(ASTRule(r, (yyvsp[0].code)));
}
break;
case 26:
{
- (yyval.regexp) = RegExp::make_cat((yyvsp[-2].regexp), RegExp::make_cat(RegExp::make_tag(context.input.get_cline(), 0, NULL), (yyvsp[0].regexp)));
+ (yyval.regexp) = ast_cat((yyvsp[-2].regexp), ast_cat(ast_tag(context.input.get_cline(), 0, NULL), (yyvsp[0].regexp)));
}
break;
{
if (context.input.opts->posix_captures) {
- (yyvsp[0].regexp) = RegExp::make_cap((yyvsp[0].regexp));
+ (yyvsp[0].regexp) = ast_cap((yyvsp[0].regexp));
}
(yyval.regexp) = (yyvsp[0].regexp);
}
case 29:
{
- (yyval.regexp) = RegExp::make_alt((yyvsp[-2].regexp), (yyvsp[0].regexp));
+ (yyval.regexp) = ast_alt((yyvsp[-2].regexp), (yyvsp[0].regexp));
}
break;
case 31:
{
- (yyval.regexp) = RegExp::make_diff((yyvsp[-2].regexp), (yyvsp[0].regexp));
+ (yyval.regexp) = ast_diff((yyvsp[-2].regexp), (yyvsp[0].regexp));
}
break;
case 33:
{
- (yyval.regexp) = RegExp::make_cat((yyvsp[-1].regexp), (yyvsp[0].regexp));
+ (yyval.regexp) = ast_cat((yyvsp[-1].regexp), (yyvsp[0].regexp));
}
break;
{
switch((yyvsp[0].op)) {
- case '*': (yyval.regexp) = RegExp::make_iter((yyvsp[-1].regexp), 0, RegExp::MANY); break;
- case '+': (yyval.regexp) = RegExp::make_iter((yyvsp[-1].regexp), 1, RegExp::MANY); break;
- case '?': (yyval.regexp) = RegExp::make_iter((yyvsp[-1].regexp), 0, 1); break;
+ case '*': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, AST::MANY); break;
+ case '+': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 1, AST::MANY); break;
+ case '?': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, 1); break;
}
}
case 36:
{
- (yyval.regexp) = RegExp::make_iter((yyvsp[-1].regexp), (yyvsp[0].extop).min, (yyvsp[0].extop).max);
+ (yyval.regexp) = ast_iter((yyvsp[-1].regexp), (yyvsp[0].extop).min, (yyvsp[0].extop).max);
}
break;
context.input.fatal("can't find symbol");
}
(yyval.regexp) = i->second;
- if (context.input.opts->posix_captures && RegExp::need_wrap((yyval.regexp))) {
- (yyval.regexp) = RegExp::make_ref((yyval.regexp), *(yyvsp[0].str));
+ if (context.input.opts->posix_captures && ast_need_wrap((yyval.regexp))) {
+ (yyval.regexp) = ast_ref((yyval.regexp), *(yyvsp[0].str));
}
delete (yyvsp[0].str);
}
{
(yyval.regexp) = (yyvsp[-1].regexp);
if (context.input.opts->posix_captures) {
- (yyval.regexp) = RegExp::make_cap((yyval.regexp));
+ (yyval.regexp) = ast_cap((yyval.regexp));
}
}
emit_epilog (o, output.skeletons);
}
- RegExp::flist.clear();
+ AST::flist.clear();
Code::flist.clear();
Range::vFreeList.clear();
RangeSuffix::freeList.clear();
{
- const re2c::RegExp * regexp;
+ const re2c::AST * regexp;
re2c::Code * code;
char op;
re2c::ExtOp extop;
--- /dev/null
+#include <limits>
+
+#include "src/ast/ast.h"
+
+namespace re2c
+{
+
+free_list<AST*> AST::flist;
+
+const uint32_t AST::MANY = std::numeric_limits<uint32_t>::max();
+
+AST::AST(uint32_t l, uint32_t c, type_t t)
+ : type(t), line(l), column(c)
+{
+ flist.insert(this);
+}
+
+AST::~AST()
+{
+ flist.erase(this);
+ if (type == TAG) {
+ delete tag;
+ } else if (type == REF) {
+ delete ref.name;
+ }
+}
+
+const AST *ast_nil(uint32_t l, uint32_t c)
+{
+ return new AST(l, c, AST::NIL);
+}
+
+const AST *ast_schar(uint32_t l, uint32_t c, uint32_t x)
+{
+ AST *ast = new AST(l, c, AST::SCHAR);
+ ast->schar = x;
+ return ast;
+}
+
+const AST *ast_ichar(uint32_t l, uint32_t c, uint32_t x)
+{
+ AST *ast = new AST(l, c, AST::ICHAR);
+ ast->ichar = x;
+ return ast;
+}
+
+const AST *ast_class(uint32_t l, uint32_t c, const Range *r)
+{
+ AST *ast = new AST(l, c, AST::CLASS);
+ ast->cls = r;
+ return ast;
+}
+
+const AST *ast_dot(uint32_t l, uint32_t c)
+{
+ return new AST(l, c, AST::DOT);
+}
+
+const AST *ast_default(uint32_t l, uint32_t c)
+{
+ return new AST(l, c, AST::DEFAULT);
+}
+
+const AST *ast_alt(const AST *a1, const AST *a2)
+{
+ if (!a1) return a2;
+ if (!a2) return a1;
+ AST *ast = new AST(a1->line, a1->column, AST::ALT);
+ ast->alt.ast1 = a1;
+ ast->alt.ast2 = a2;
+ return ast;
+}
+
+const AST *ast_cat(const AST *a1, const AST *a2)
+{
+ if (!a1) return a2;
+ if (!a2) return a1;
+ AST *ast = new AST(a1->line, a1->column, AST::CAT);
+ ast->cat.ast1 = a1;
+ ast->cat.ast2 = a2;
+ return ast;
+}
+
+const AST *ast_iter(const AST *r, uint32_t n, uint32_t m)
+{
+ AST *ast = new AST(r->line, r->column, AST::ITER);
+ ast->iter.ast = r;
+ ast->iter.min = n;
+ ast->iter.max = m;
+ return ast;
+}
+
+const AST *ast_diff(const AST *a1, const AST *a2)
+{
+ AST *ast = new AST(a1->line, a1->column, AST::DIFF);
+ ast->cat.ast1 = a1;
+ ast->cat.ast2 = a2;
+ return ast;
+}
+
+const AST *ast_tag(uint32_t l, uint32_t c, const std::string *t)
+{
+ AST *ast = new AST(l, c, AST::TAG);
+ ast->tag = t;
+ return ast;
+}
+
+const AST *ast_cap(const AST *r)
+{
+ AST *ast = new AST(r->line, r->column, AST::CAP);
+ ast->cap = r;
+ return ast;
+}
+
+const AST *ast_ref(const AST *r, const std::string &n)
+{
+ AST *ast = new AST(r->line, r->column, AST::REF);
+ ast->ref.ast = r;
+ ast->ref.name = new std::string(n);
+ return ast;
+}
+
+bool ast_need_wrap(const AST *ast)
+{
+ switch (ast->type) {
+ case AST::ITER:
+ case AST::NIL:
+ case AST::SCHAR:
+ case AST::ICHAR:
+ case AST::CLASS:
+ case AST::DOT:
+ case AST::DEFAULT:
+ case AST::TAG:
+ case AST::CAP:
+ return false;
+ case AST::ALT:
+ case AST::CAT:
+ case AST::DIFF:
+ case AST::REF:
+ return true;
+ }
+ assert(false);
+}
+
+} // namespace re2c
--- /dev/null
+#ifndef _RE2C_AST_AST_
+#define _RE2C_AST_AST_
+
+#include "src/util/c99_stdint.h"
+#include <string>
+#include <vector>
+
+#include "src/rule.h"
+#include "src/util/free_list.h"
+#include "src/util/range.h"
+
+namespace re2c
+{
+
+/* AST must be immutable and independent of options */
+struct AST
+{
+ static free_list<AST*> flist;
+ static const uint32_t MANY;
+
+ enum type_t
+ { NIL, SCHAR, ICHAR, CLASS, DOT, DEFAULT
+ , ALT, CAT, ITER, DIFF, TAG, CAP
+ , REF } type;
+ union {
+ uint32_t schar;
+ uint32_t ichar;
+ const Range *cls;
+ struct {
+ const AST *ast1;
+ const AST *ast2;
+ } alt;
+ struct {
+ const AST *ast1;
+ const AST *ast2;
+ } cat;
+ struct {
+ const AST *ast;
+ uint32_t min;
+ uint32_t max;
+ } iter;
+ struct {
+ const AST *ast1;
+ const AST *ast2;
+ } diff;
+ const std::string *tag;
+ const AST *cap;
+ struct {
+ const AST *ast;
+ const std::string *name;
+ } ref;
+ };
+ uint32_t line;
+ uint32_t column;
+
+ AST(uint32_t l, uint32_t c, type_t t);
+ ~AST();
+};
+
+struct ASTRule
+{
+ const AST *ast;
+ const Code *code;
+
+ ASTRule(const AST *r, const Code *c)
+ : ast(r)
+ , code(c)
+ {}
+};
+
+const AST *ast_nil(uint32_t l, uint32_t c);
+const AST *ast_schar(uint32_t l, uint32_t c, uint32_t x);
+const AST *ast_ichar(uint32_t l, uint32_t c, uint32_t x);
+const AST *ast_class(uint32_t l, uint32_t c, const Range *r);
+const AST *ast_dot(uint32_t l, uint32_t c);
+const AST *ast_default(uint32_t l, uint32_t c);
+const AST *ast_alt(const AST *r1, const AST *r2);
+const AST *ast_cat(const AST *r1, const AST *r2);
+const AST *ast_iter(const AST *r, uint32_t n, uint32_t m);
+const AST *ast_diff(const AST *r1, const AST *r2);
+const AST *ast_tag(uint32_t l, uint32_t c, const std::string *t);
+const AST *ast_cap(const AST *r);
+const AST *ast_ref(const AST *r, const std::string &n);
+bool ast_need_wrap(const AST *ast);
+
+} // namespace re2c
+
+#endif // _RE2C_AST_AST_
#include "src/re/encoding/enc.h"
#include "src/ast/extop.h"
#include "src/ast/input.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/ast/scanner.h"
#include "src/ast/parser.h" // needed by "y.tab.h"
#include "src/ast/unescape.h"
fatal("tags are only allowed with '-T, --tags' option");
}
const std::string *name = new std::string(tok + 1, tok_len() - 1);
- yylval.regexp = RegExp::make_tag(cline, get_column(), name);
+ yylval.regexp = ast_tag(cline, get_column(), name);
return TOKEN_REGEXP;
}
yylval.str = new std::string (tok, tok_len());
return TOKEN_ID;
} else {
- const RegExp *r = NULL;
+ const AST *r = NULL;
const bool casing = opts->bCaseInsensitive || opts->bCaseInverted;
for (char *s = tok; s < cur; ++s) {
const uint32_t
c = static_cast<uint8_t>(*s),
column = static_cast<uint32_t>(s - pos);
- r = RegExp::make_cat(r, casing
- ? RegExp::make_ichar(cline, column, c)
- : RegExp::make_schar(cline, column, c));
+ r = ast_cat(r, casing
+ ? ast_ichar(cline, column, c)
+ : ast_schar(cline, column, c));
}
- yylval.regexp = r ? r : RegExp::make_nil(cline, get_column());
+ yylval.regexp = r ? r : ast_nil(cline, get_column());
return TOKEN_REGEXP;
}
}
"." {
- yylval.regexp = RegExp::make_dot(cline, get_column());
+ yylval.regexp = ast_dot(cline, get_column());
return TOKEN_REGEXP;
}
}
}
-const RegExp *Scanner::lex_cls(bool neg)
+const AST *Scanner::lex_cls(bool neg)
{
const uint32_t column = get_column();
Range *r = NULL, *s;
if (neg) {
r = Range::sub(opts->encoding.fullRange(), r);
}
- return RegExp::make_class(cline, column, r);
+ return ast_class(cline, column, r);
}
uint32_t Scanner::lex_cls_chr()
*/
}
-const RegExp *Scanner::lex_str(char quote, bool casing)
+const AST *Scanner::lex_str(char quote, bool casing)
{
- const RegExp *r = NULL;
+ const AST *r = NULL;
for (bool end;;) {
const uint32_t c = lex_str_chr(quote, end);
if (end) {
- return r ? r : RegExp::make_nil(cline, get_column());
+ return r ? r : ast_nil(cline, get_column());
}
- r = RegExp::make_cat(r, casing
- ? RegExp::make_ichar(cline, get_column(), c)
- : RegExp::make_schar(cline, get_column(), c));
+ r = ast_cat(r, casing
+ ? ast_ichar(cline, get_column(), c)
+ : ast_schar(cline, get_column(), c));
}
}
#include <string>
#include "src/code/output.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/ast/scanner.h"
#include "src/util/smart_ptr.h"
struct spec_t
{
std::string name;
- std::vector<RegExpRule> rules;
+ std::vector<ASTRule> rules;
std::vector<const Code*> defs;
std::vector<const Code*> setup;
typedef std::vector<spec_t> specs_t;
typedef std::set<std::string> CondList;
-typedef std::map<std::string, const RegExp *> symtab_t;
+typedef std::map<std::string, const AST*> symtab_t;
typedef std::vector<smart_ptr<DFA> > dfas_t;
struct context_t
#include "src/skeleton/skeleton.h"
#include "src/ast/extop.h"
#include "src/ast/parser.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/ast/scanner.h"
#include "src/util/free_list.h"
#include "src/util/range.h"
for (i = b; i != e; ++i) {
if (!i->defs.empty()) {
const Code *c = i->defs[0];
- const RegExp *r = RegExp::make_default(c->fline, 0);
- i->rules.push_back(RegExpRule(r, c));
+ const AST *r = ast_default(c->fline, 0);
+ i->rules.push_back(ASTRule(r, c));
}
}
%parse-param {re2c::context_t &context}
%union {
- const re2c::RegExp * regexp;
+ const re2c::AST * regexp;
re2c::Code * code;
char op;
re2c::ExtOp extop;
rule
: trailexpr TOKEN_CODE {
- find(context.specs, "").rules.push_back(RegExpRule($1, $2));
+ find(context.specs, "").rules.push_back(ASTRule($1, $2));
}
| '*' TOKEN_CODE {
| '<' clist '>' trailexpr ccode {
for(CondList::const_iterator i = $2->begin(); i != $2->end(); ++i) {
- find(context.specs, *i).rules.push_back(RegExpRule($4, $5));
+ find(context.specs, *i).rules.push_back(ASTRule($4, $5));
}
delete $2;
}
}
| '<' '>' ccode {
- const RegExp *r = RegExp::make_nil(context.input.get_cline(), 0);
- find(context.specs, "0").rules.push_back(RegExpRule(r, $3));
+ const AST *r = ast_nil(context.input.get_cline(), 0);
+ find(context.specs, "0").rules.push_back(ASTRule(r, $3));
};
ccode
trailexpr
: capexpr
| capexpr '/' expr {
- $$ = RegExp::make_cat($1, RegExp::make_cat(RegExp::make_tag(context.input.get_cline(), 0, NULL), $3));
+ $$ = ast_cat($1, ast_cat(ast_tag(context.input.get_cline(), 0, NULL), $3));
};
capexpr
: expr {
if (context.input.opts->posix_captures) {
- $1 = RegExp::make_cap($1);
+ $1 = ast_cap($1);
}
$$ = $1;
};
}
| expr '|' diff
{
- $$ = RegExp::make_alt($1, $3);
+ $$ = ast_alt($1, $3);
}
;
}
| diff '\\' term
{
- $$ = RegExp::make_diff($1, $3);
+ $$ = ast_diff($1, $3);
}
;
}
| term factor
{
- $$ = RegExp::make_cat($1, $2);
+ $$ = ast_cat($1, $2);
}
;
: primary
| primary closes {
switch($2) {
- case '*': $$ = RegExp::make_iter($1, 0, RegExp::MANY); break;
- case '+': $$ = RegExp::make_iter($1, 1, RegExp::MANY); break;
- case '?': $$ = RegExp::make_iter($1, 0, 1); break;
+ case '*': $$ = ast_iter($1, 0, AST::MANY); break;
+ case '+': $$ = ast_iter($1, 1, AST::MANY); break;
+ case '?': $$ = ast_iter($1, 0, 1); break;
}
} | primary TOKEN_CLOSESIZE {
- $$ = RegExp::make_iter($1, $2.min, $2.max);
+ $$ = ast_iter($1, $2.min, $2.max);
};
closes
context.input.fatal("can't find symbol");
}
$$ = i->second;
- if (context.input.opts->posix_captures && RegExp::need_wrap($$)) {
- $$ = RegExp::make_ref($$, *$1);
+ if (context.input.opts->posix_captures && ast_need_wrap($$)) {
+ $$ = ast_ref($$, *$1);
}
delete $1;
} | '(' expr ')' {
$$ = $2;
if (context.input.opts->posix_captures) {
- $$ = RegExp::make_cap($$);
+ $$ = ast_cap($$);
}
};
emit_epilog (o, output.skeletons);
}
- RegExp::flist.clear();
+ AST::flist.clear();
Code::flist.clear();
Range::vFreeList.clear();
RangeSuffix::freeList.clear();
+++ /dev/null
-#include <limits>
-
-#include "src/ast/regexp.h"
-
-namespace re2c
-{
-
-free_list<RegExp*> RegExp::flist;
-
-const uint32_t RegExp::MANY = std::numeric_limits<uint32_t>::max();
-
-bool RegExp::need_wrap(const RegExp *re)
-{
- switch (re->type) {
- case RegExp::ITER:
- case RegExp::NIL:
- case RegExp::SCHAR:
- case RegExp::ICHAR:
- case RegExp::CLASS:
- case RegExp::DOT:
- case RegExp::DEFAULT:
- case RegExp::TAG:
- case RegExp::CAP:
- return false;
- case RegExp::ALT:
- case RegExp::CAT:
- case RegExp::DIFF:
- case RegExp::REF:
- return true;
- }
- assert(false);
-}
-
-} // namespace re2c
+++ /dev/null
-#ifndef _RE2C_AST_REGEXP_
-#define _RE2C_AST_REGEXP_
-
-#include "src/util/c99_stdint.h"
-#include <set>
-#include <string>
-#include <vector>
-
-#include "src/conf/warn.h"
-#include "src/rule.h"
-#include "src/util/free_list.h"
-#include "src/util/range.h"
-
-namespace re2c
-{
-
-struct Opt;
-
-struct RegExp
-{
- static free_list<RegExp*> flist;
- static const uint32_t MANY;
-
- enum type_t {NIL, SCHAR, ICHAR, CLASS, DOT, DEFAULT, ALT, CAT, ITER, DIFF, TAG, CAP, REF} type;
- union
- {
- uint32_t schar;
- uint32_t ichar;
- const Range *cls;
- struct
- {
- const RegExp *re1;
- const RegExp *re2;
- } alt;
- struct
- {
- const RegExp *re1;
- const RegExp *re2;
- } cat;
- struct
- {
- const RegExp *re;
- uint32_t min;
- uint32_t max;
- } iter;
- struct
- {
- const RegExp *re1;
- const RegExp *re2;
- } diff;
- const std::string *tag;
- const RegExp *cap;
- struct
- {
- const RegExp *re;
- const std::string *name;
- } ref;
- };
- uint32_t line;
- uint32_t column;
-
- static const RegExp *make_nil(uint32_t l, uint32_t c)
- {
- return new RegExp(l, c, NIL);
- }
- static const RegExp *make_schar(uint32_t l, uint32_t c, uint32_t x)
- {
- RegExp *re = new RegExp(l, c, SCHAR);
- re->schar = x;
- return re;
- }
- static const RegExp *make_ichar(uint32_t l, uint32_t c, uint32_t x)
- {
- RegExp *re = new RegExp(l, c, ICHAR);
- re->ichar = x;
- return re;
- }
- static const RegExp *make_class(uint32_t l, uint32_t c, const Range *r)
- {
- RegExp *re = new RegExp(l, c, CLASS);
- re->cls = r;
- return re;
- }
- static const RegExp *make_dot(uint32_t l, uint32_t c)
- {
- return new RegExp(l, c, DOT);
- }
- static const RegExp *make_default(uint32_t l, uint32_t c)
- {
- return new RegExp(l, c, DEFAULT);
- }
- static const RegExp *make_alt(const RegExp *r1, const RegExp *r2)
- {
- if (!r1) return r2;
- if (!r2) return r1;
- RegExp *re = new RegExp(r1->line, r1->column, ALT);
- re->alt.re1 = r1;
- re->alt.re2 = r2;
- return re;
- }
- static const RegExp *make_cat(const RegExp *r1, const RegExp *r2)
- {
- if (!r1) return r2;
- if (!r2) return r1;
- RegExp *re = new RegExp(r1->line, r1->column, CAT);
- re->cat.re1 = r1;
- re->cat.re2 = r2;
- return re;
- }
- static const RegExp *make_iter(const RegExp *r, uint32_t n, uint32_t m)
- {
- RegExp *re = new RegExp(r->line, r->column, ITER);
- re->iter.re = r;
- re->iter.min = n;
- re->iter.max = m;
- return re;
- }
- static const RegExp *make_diff(const RegExp *r1, const RegExp *r2)
- {
- RegExp *re = new RegExp(r1->line, r1->column, DIFF);
- re->cat.re1 = r1;
- re->cat.re2 = r2;
- return re;
- }
- static const RegExp *make_tag(uint32_t l, uint32_t c, const std::string *t)
- {
- RegExp *re = new RegExp(l, c, TAG);
- re->tag = t;
- return re;
- }
- static const RegExp *make_cap(const RegExp *r)
- {
- RegExp *re = new RegExp(r->line, r->column, CAP);
- re->cap = r;
- return re;
- }
- static const RegExp *make_ref(const RegExp *r, const std::string &n)
- {
- RegExp *re = new RegExp(r->line, r->column, REF);
- re->ref.re = r;
- re->ref.name = new std::string(n);
- return re;
- }
- inline ~RegExp()
- {
- flist.erase(this);
- if (type == TAG) {
- delete tag;
- } else if (type == REF) {
- delete ref.name;
- }
- }
- static bool need_wrap(const RegExp *re);
-
-private:
- inline RegExp(uint32_t l, uint32_t c, type_t t)
- : type(t), line(l), column(c)
- {
- flist.insert(this);
- }
-};
-
-struct RegExpRule
-{
- const RegExp *re;
- const Code *code;
-
- RegExpRule(const RegExp *r, const Code *c)
- : re(r)
- , code(c)
- {}
-};
-
-} // end namespace re2c
-
-#endif // _RE2C_AST_REGEXP_
{
class Range;
-struct RegExp;
+struct AST;
class OutputFile;
struct ScannerState
void set_sourceline ();
uint32_t lex_cls_chr();
uint32_t lex_str_chr(char quote, bool &end);
- const RegExp *lex_cls(bool neg);
- const RegExp *lex_str(char quote, bool casing);
+ const AST *lex_cls(bool neg);
+ const AST *lex_str(char quote, bool casing);
void lex_conf ();
void lex_conf_encoding_policy();
void lex_conf_input();
#include "src/adfa/action.h"
#include "src/adfa/adfa.h"
#include "src/skeleton/skeleton.h"
-#include "src/ast/regexp.h"
#include "src/util/string_utils.h"
namespace re2c
#include "src/dfa/dump.h"
#include "src/nfa/nfa.h"
#include "src/skeleton/skeleton.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
namespace re2c {
{
const opt_t *opts = output.source.block().opts;
Warn &warn = output.source.warn;
- const std::vector<RegExpRule> &rules = spec.rules;
+ const std::vector<ASTRule> &rules = spec.rules;
const size_t defrule = spec.defs.empty()
? Rule::NONE
: rules.size() - 1;
+#include <assert.h>
#include <string.h>
#include "src/dfa/cfg/cfg.h"
#include "src/dfa/dump.h"
#include "src/dfa/find_state.h"
#include "src/nfa/nfa.h"
-#include "src/ast/regexp.h"
#include "src/util/range.h"
namespace re2c
#include "src/tag.h"
#include "src/tcmd.h"
#include "src/dfa/tagpool.h"
-#include "src/ast/regexp.h"
#include "src/util/forbid_copy.h"
namespace re2c
iter = estimate(re->iter.re),
min = re->iter.min,
max = re->iter.max;
- return max == RegExp::MANY
+ return max == AST::MANY
? iter * min + 1
: iter * max + (max - min);
}
max = re->iter.max;
const RE *iter = re->iter.re;
// see note [counted repetition and iteration expansion]
- if (max == RegExp::MANY) {
+ if (max == AST::MANY) {
nfa_state_t *q = &nfa.states[nfa.size++];
s = re_to_nfa(nfa, nrule, iter, q);
q->make_alt(nrule, s, t);
* (the way invalid code points are treated).
*/
-static RE *ast_to_re(RESpec &spec, const RegExp *ast, size_t &ncap)
+static RE *ast_to_re(RESpec &spec, const AST *ast, size_t &ncap)
{
RE::alc_t &alc = spec.alc;
std::vector<Tag> &tags = spec.tags;
switch (ast->type) {
default: assert(false);
- case RegExp::NIL:
+ case AST::NIL:
return re_nil(alc);
- case RegExp::ALT: {
- RE *x = ast_to_re(spec, ast->alt.re1, ncap);
- RE *y = ast_to_re(spec, ast->alt.re2, ncap);
+ case AST::ALT: {
+ RE *x = ast_to_re(spec, ast->alt.ast1, ncap);
+ RE *y = ast_to_re(spec, ast->alt.ast2, ncap);
return re_alt(alc, x, y);
}
- case RegExp::CAT: {
- RE *x = ast_to_re(spec, ast->cat.re1, ncap);
- RE *y = ast_to_re(spec, ast->cat.re2, ncap);
+ case AST::CAT: {
+ RE *x = ast_to_re(spec, ast->cat.ast1, ncap);
+ RE *y = ast_to_re(spec, ast->cat.ast2, ncap);
return re_cat(alc, x, y);
}
- case RegExp::TAG: {
+ case AST::TAG: {
RE *t = re_tag(alc, tags.size(), false);
tags.push_back(Tag(ast->tag));
return t;
}
- case RegExp::CAP: {
- const RegExp *x = ast->cap;
- if (x->type == RegExp::REF) x = x->ref.re;
+ case AST::CAP: {
+ const AST *x = ast->cap;
+ if (x->type == AST::REF) x = x->ref.ast;
RE *t1 = re_tag(alc, tags.size(), false);
tags.push_back(Tag(3 * ncap));
++ncap;
return re_cat(alc, t1, re_cat(alc, ast_to_re(spec, x, ncap), t2));
}
- case RegExp::REF:
+ case AST::REF:
error("implicit grouping is forbidden with '--posix-captures'"
" option, please wrap '%s' in capturing parenthesis",
ast->ref.name->c_str());
exit(1);
- case RegExp::ITER: {
+ case AST::ITER: {
const uint32_t
n = ast->iter.min,
n1 = std::max(n, 1u),
m = std::max(n, ast->iter.max);
- const RegExp *x = ast->iter.re;
+ const AST *x = ast->iter.ast;
RE *t1 = NULL, *t2 = NULL, *t3 = NULL;
- if (x->type == RegExp::CAP) {
+ if (x->type == AST::CAP) {
x = x->cap;
- if (x->type == RegExp::REF) x = x->ref.re;
+ if (x->type == AST::REF) x = x->ref.ast;
t1 = re_tag(alc, tags.size(), false);
tags.push_back(Tag(3 * ncap));
}
return y;
}
- case RegExp::SCHAR:
+ case AST::SCHAR:
return re_schar(alc, ast->line, ast->column, ast->schar, opts);
- case RegExp::ICHAR:
+ case AST::ICHAR:
return re_ichar(alc, ast->line, ast->column, ast->ichar, opts);
- case RegExp::CLASS:
+ case AST::CLASS:
return re_class(alc, ast->line, ast->column, ast->cls, opts, warn);
- case RegExp::DIFF: {
- RE *x = ast_to_re(spec, ast->diff.re1, ncap);
- RE *y = ast_to_re(spec, ast->diff.re2, ncap);
+ case AST::DIFF: {
+ RE *x = ast_to_re(spec, ast->diff.ast1, ncap);
+ RE *y = ast_to_re(spec, ast->diff.ast2, ncap);
if (x->type != RE::SYM || y->type != RE::SYM) {
fatal_error(ast->line, ast->column, "can only difference char sets");
}
return re_class(alc, ast->line, ast->column, Range::sub(x->sym, y->sym), opts, warn);
}
- case RegExp::DOT: {
+ case AST::DOT: {
uint32_t c = '\n';
if (!opts->encoding.encode(c)) {
fatal_error(ast->line, ast->column, "bad code point: '0x%X'", c);
return re_class(alc, ast->line, ast->column,
Range::sub(opts->encoding.fullRange(), Range::sym(c)), opts, warn);
}
- case RegExp::DEFAULT:
+ case AST::DEFAULT:
// see note [default regexp]
return re_sym(alc, Range::ran(0, opts->encoding.nCodeUnits()));
}
assert_tags_used_once(rule, tags);
}
-RESpec::RESpec(const std::vector<RegExpRule> &ast, const opt_t *o, Warn &w)
+RESpec::RESpec(const std::vector<ASTRule> &ast, const opt_t *o, Warn &w)
: alc()
, res()
, charset(*new std::vector<uint32_t>)
{
for (size_t i = 0; i < ast.size(); ++i) {
size_t ltag = tags.size(), ncap = 0;
- res.push_back(ast_to_re(*this, ast[i].re, ncap));
+ res.push_back(ast_to_re(*this, ast[i].ast, ncap));
init_rule(rules[i], ast[i].code, tags, ltag, ncap);
}
}
#include "src/conf/opt.h"
#include "src/rule.h"
-#include "src/ast/regexp.h"
+#include "src/ast/ast.h"
#include "src/util/forbid_copy.h"
#include "src/util/range.h"
#include "src/util/slab_allocator.h"
const opt_t *opts;
Warn &warn;
- explicit RESpec(const std::vector<RegExpRule> &ast, const opt_t *o, Warn &w);
+ explicit RESpec(const std::vector<ASTRule> &ast, const opt_t *o, Warn &w);
FORBID_COPY(RESpec);
};
#include "src/util/c99_stdint.h"
+#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include <algorithm>
#include <string.h>