1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
driver.cc
*/
#include "driver.h"
#include <bobcat/pattern>
using namespace std;
using namespace FBB;
void showSubstr(string const &str)
{
static int
count = 1;
cout << "String " << count++ << " is '" << str << "'\n";
}
int main(int argc, char **argv)
{
{
Pattern one("one");
Pattern two(one);
Pattern three("a");
Pattern four;
three = two;
}
try
{
Pattern pattern("aap|noot|mies");
{
Pattern extra(Pattern(pattern));
}
cerr << "Here we are\n";
try
{
pattern.match("noot");
cout << "noot matches\n";
}
catch (Errno const &e)
{
cout << e.what() << ": noot doesn't match" << endl;
}
}
catch (Errno const &e)
{
cout << e.what() << ": compilation failed" << endl;
}
if (pattern << "noot")
cout << "noot matches\n";
else
cout << "noot didn't match\n";
/*
gewenst patroon:
\\
aanbieden aan de de patroon-vertaler:
\\\\
dus in de string constante:
\\\\\\\\
gewenst:
\d
aanbieden aan de patroon vertaler:
\d
in de string constante:
\\d
*/
string
pat = "(\\\\\\\\)*(\\\\\\$|\\$(\\d)+)";
while (true)
{
cout << "Patroon: '" << pat << "'\n";
try
{
Pattern
patt(pat, argv[1] != 0);
Pattern
pattern;
pattern = patt;
pattern.setPattern(pat, argv[1] != 0);
while (true)
{
string
st;
cerr << "string to match : " << flush;
getline(cin, st);
if (st == "")
break;
cout << "String: '" << st << "'\n";
try
{
pattern.match(st);
Pattern p3(pattern);
cerr << "before: " << p3.before() << endl;
cerr << "matched: " << p3.matched() << endl;
cerr << "beyond: " << pattern.beyond() << endl;
cerr << "end() = " << pattern.end() << endl;
for (size_t idx = 0; idx < pattern.end(); ++idx)
{
string
str = pattern[idx];
if (str == "")
cerr << "part " << idx << " not present\n";
else
{
Pattern::Position
pos = pattern.position(idx);
cerr << "part " << idx << ": '" << str << "' (" <<
pos.first << "-" << pos.second << ")\n";
}
}
}
catch (Errno const &e)
{
cout << e.what() << ": " << st << " doesn't match" << endl;
continue;
}
}
}
catch (Errno const &e)
{
cout << e.what() << ": compilation failed" << endl;
}
cout << "New pattern: " << flush;
if (!getline(cin, pat) || !pat.length())
return 0;
}
}
|