#include "RegexExpression.h"
namespace
{
namespace
{
class
:
public
<
bool
,
*>
{
public
:
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(
->
!=
expected
->
)
return
false
;
if
(
->
.
()!=
expected
->
.
())
return
false
;
for
(
=
0
;
i
<
->
.
();
i
++)
{
if
(
->
i
]
expected
->
i
])
return
false
;
}
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(
->
!=
expected
->
)
return
false
;
if
(
->
!=
expected
->
)
return
false
;
if
(
->
!=
expected
->
)
return
false
;
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(!
(
->
,
expected
->
.
()))
return
false
;
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(!
(
->
,
expected
->
.
()))
return
false
;
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(
->
!=
expected
->
)
return
false
;
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(
->
!=
expected
->
)
return
false
;
if
(
->
!=
expected
->
)
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(!
(
->
,
expected
->
.
()))
return
false
;
return
true
;
}
return
false
;
}
bool
(
*
,
*
)
{
*
=
dynamic_cast
<
*>(
);
if
(
expected
)
{
if
(
->
!=
expected
->
)
return
false
;
return
true
;
}
return
false
;
}
};
class
:
public
<
bool
,
void
*>
{
public
:
bool
(
*
,
void
*
)
{
return
true
;
}
bool
(
*
,
void
*
)
{
return
->
&&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
(
->
,
0
) &&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
(
->
,
0
) &&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
};
class
:
public
<
bool
,
void
*>
{
public
:
bool
(
*
,
void
*
)
{
return
true
;
}
bool
(
*
,
void
*
)
{
return
->
&&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
(
->
,
0
) &&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
(
->
,
0
) &&
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
(
->
,
0
);
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
bool
(
*
,
void
*
)
{
return
false
;
}
};
class
{
public
:
::
;
};
class
:
public
<
void
,
*>
{
public
:
virtual
void
(
*
,
*
,
)=
0
;
void
(
*
,
::
&
,
*
)
{
if
(
->
)
{
wchar_t
=
1
;
for
(
=
0
;
i
<
.
();
i
++)
{
=
i
];
if
(
range
.
>
begin
)
{
(
,
,
(
begin
,
range
.
-
1
));
}
begin
=
range
.
+
1
;
}
if
(
begin
<=
65535
)
{
(
,
,
(
begin
,
65535
));
}
}
else
{
for
(
=
0
;
i
<
.
();
i
++)
{
(
,
,
i
]);
}
}
}
void
(
*
,
*
)
{
(
->
,
);
}
void
(
*
,
*
)
{
(
->
,
);
(
->
,
);
}
void
(
*
,
*
)
{
(
->
,
);
(
->
,
);
}
void
(
*
,
*
)
{
}
void
(
*
,
*
)
{
}
void
(
*
,
*
)
{
(
->
,
);
}
void
(
*
,
*
)
{
}
void
(
*
,
*
)
{
(
->
,
);
}
void
(
*
,
*
)
{
(
->
,
);
}
void
(
*
,
*
)
{
}
};
class
BuildNormalizedCharSetAlgorithm
:
public
{
public
:
void
(
*
,
*
,
)
{
=
0
;
while
(
index
<
->
.
())
{
=
->
index
];
if
(
current
||
current
>
)
{
index
++;
}
else
if
(
current
.
<
.
)
{
->
.
(
index
);
->
.
(
(
current
.
,
.
-
1
));
->
.
(
(
.
,
current
.
));
index
++;
}
else
if
(
current
.
>
.
)
{
->
.
(
(
.
,
current
.
-
1
));
.
=
current
.
;
}
else
if
(
current
.
<
.
)
{
.
=
current
.
+
1
;
index
++;
}
else
if
(
current
.
>
.
)
{
->
.
(
index
);
->
.
(
);
->
.
(
(
.
+
1
,
current
.
));
return
;
}
else
{
return
;
}
}
->
.
(
);
}
void
(
*
,
*
)
{
(
,
->
,
);
}
};
class
SetNormalizedCharSetAlgorithm
:
public
{
public
:
void
(
*
,
*
,
)
{
for
(
=
0
;
j
<
->
.
();
j
++)
{
=
->
j
];
if
(
.
<=
targetRange
.
&&
targetRange
.
<=
.
)
{
->
.
(
targetRange
);
}
}
}
void
(
*
,
*
)
{
::
;
(
source
,
->
);
->
.
();
(
,
source
,
);
->
=
false
;
}
};
class
{
public
:
::
;
*
;
};
class
:
public
<
::
,
*>
{
public
:
::
(
*
,
*
)
{
<
>
=
new
;
(
result
,
->
);
result
=
->
;
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
=
->
;
result
=
->
;
result
=
->
;
result
(
->
,
);
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
(
->
,
);
result
(
->
,
);
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
(
->
,
);
result
(
->
,
);
return
result
;
}
::
(
*
,
*
)
{
return
new
;
}
::
(
*
,
*
)
{
return
new
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
(
->
,
);
result
->
;
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
->
;
result
=
->
;
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
(
->
,
);
return
result
;
}
::
(
*
,
*
)
{
<
>
=
new
;
result
(
->
,
);
return
result
;
}
::
(
*
,
*
)
{
if
(
->
definitions
.
().
(
->
))
{
::
=
->
definitions
->
];
if
(
reference
)
{
return
reference
;
}
else
{
throw
(
L"Regular expression syntax error: Found reference loops in\""
+
->
+
L"\"."
,
L"vl::regex_internal::RegexExpression::Merge"
,
L""
);
}
}
else
if
(
->
regex
->
definitions
.
().
(
->
))
{
->
definitions
.
(
->
,
0
);
::
=
(
->
regex
->
definitions
->
],
);
->
definitions
.
(
->
,
result
);
return
result
;
}
else
{
throw
(
L"Regular expression syntax error: Cannot find sub expression reference\""
+
->
+
L"\"."
,
L"vl::regex_internal::RegexExpression::Merge"
,
L""
);
}
}
};
class
{
public
:
::
;
};
class
{
public
:
*
;
*
;
()
{
=
0
;
=
0
;
}
};
class
:
public
<
,
*>
{
public
:
(
,
,
*
)
{
if
(
.
)
{
->
(
.
,
.
);
.
=
.
;
return
;
}
else
{
return
;
}
}
(
*
,
*
)
{
;
nfa
.
=
->
();
nfa
.
=
->
();
for
(
=
0
;
i
<
->
.
();
i
++)
{
->
(
nfa
.
,
nfa
.
,
->
i
]);
}
return
nfa
;
}
(
*
,
*
)
{
;
for
(
=
0
;
i
<
->
;
i
++)
{
=
(
->
,
);
head
(
head
,
body
,
);
}
if
(
->
==-
1
)
{
=
(
->
,
);
if
(!
head
.
)
{
head
.
=
head
.
=
->
();
}
*
=
head
.
;
*
=
->
();
if
(
->
)
{
->
(
loopBegin
,
body
.
);
->
(
body
.
,
loopBegin
);
->
(
loopBegin
,
loopEnd
);
}
else
{
->
(
loopBegin
,
loopEnd
);
->
(
loopBegin
,
body
.
);
->
(
body
.
,
loopBegin
);
}
head
.
=
loopEnd
;
}
else
if
(
->
>
->
)
{
for
(
=
->
;
i
<
->
;
i
++)
{
=
(
->
,
);
*
=
->
();
*
=
->
();
if
(
->
)
{
->
(
start
,
body
.
);
->
(
body
.
,
end
);
->
(
start
,
end
);
}
else
{
->
(
start
,
end
);
->
(
start
,
body
.
);
->
(
body
.
,
end
);
}
body
.
=
start
;
body
.
=
end
;
head
(
head
,
body
,
);
}
}
return
head
;
}
(
*
,
*
)
{
=
(
->
,
);
=
(
->
,
);
return
(
a
,
b
,
);
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
=
(
->
,
);
=
(
->
,
);
->
(
result
.
,
a
.
);
->
(
a
.
,
result
.
);
->
(
result
.
,
b
.
);
->
(
b
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
->
(
result
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
->
(
result
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
=-
1
;
if
(
->
!=
L""
)
{
capture
=
->
.
(
->
);
if
(
capture
==-
1
)
{
capture
=
->
.
();
->
.
(
->
);
}
}
=
(
->
,
);
->
(
result
.
,
body
.
,
capture
);
->
(
body
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
=-
1
;
if
(
->
!=
L""
)
{
capture
=
->
.
(
->
);
if
(
capture
==-
1
)
{
capture
=
->
.
();
->
.
(
->
);
}
}
;
result
.
=
->
();
result
.
=
->
();
->
(
result
.
,
result
.
,
capture
,
->
);
return
result
;
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
=
(
->
,
);
->
(
result
.
,
body
.
);
->
(
body
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
;
result
.
=
->
();
result
.
=
->
();
=
(
->
,
);
->
(
result
.
,
body
.
);
->
(
body
.
,
result
.
);
->
(
result
.
,
result
.
);
return
result
;
}
(
*
,
*
)
{
CHECK_FAIL(L"RegexExpression::GenerateEpsilonNfa()#UsingExpression cannot create state machine.");
do
{
throw
(
L"RegexExpression::GenerateEpsilonNfa()#UsingExpression cannot create state machine."
);}
while
(
0
);
}
};
bool
::
(
vl
::
regex_internal
::
*
)
{
return
().
(
this
,
);
}
bool
::
()
{
return
().
(
this
,
0
);
}
bool
::
()
{
return
().
(
this
,
0
);
}
void
::
(
::
&
)
{
;
BuildNormalizedCharSetAlgorithm
().
(
this
, &
normalized
);
SetNormalizedCharSetAlgorithm
().
(
this
, &
normalized
);
(
,
normalized
.
);
}
void
::
(
::
&
)
{
;
(
normalized
.
,
);
BuildNormalizedCharSetAlgorithm
().
(
this
, &
normalized
);
(
,
normalized
.
);
}
void
::
(
::
&
)
{
;
(
normalized
.
,
);
SetNormalizedCharSetAlgorithm
().
(
this
, &
normalized
);
}
::
::
()
{
::
=
new
;
=
().
(
this
,
automaton
.
());
automaton
=
result
.
;
result
.
->
=
true
;
return
automaton
;
}
bool
::
(
)
{
if
(
.
>
.
)
{
wchar_t
=
.
;
.
=
.
;
.
=
t
;
}
for
(
=
0
;
i
<
.
();
i
++)
{
if
(!(
i
] ||
>
i
]))
{
return
false
;
}
}
.
(
);
return
true
;
}
::
::
()
{
;
merge
.
regex
=
this
;
return
().
(
, &
merge
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
void
::
(
IRegexExpressionAlgorithm
&
)
{
.
(
this
);
}
}
}