@@ -284,7 +284,7 @@ void Grammar::parseUnaryOperators(const vector<Expansion *> & expansions, vector
284
284
285
285
while (expansionIterator != expansions.end ())
286
286
{
287
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
287
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
288
288
{
289
289
if (expansionFound)
290
290
{
@@ -356,7 +356,7 @@ void Grammar::parseUnaryOperators(const vector<Expansion *> & expansions, vector
356
356
{
357
357
if (foundStart)
358
358
{
359
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION ) // Could contain the ending }
359
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator)) // Could contain the ending }
360
360
{
361
361
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
362
362
if (Grammar::stringStartsWith (up->getSection (), " }" )) // Found the end of the tag!
@@ -403,7 +403,7 @@ void Grammar::parseUnaryOperators(const vector<Expansion *> & expansions, vector
403
403
else
404
404
{
405
405
// Looking for a starting bracket {
406
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION ) // May contain the { we're looking for
406
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator)) // May contain the { we're looking for
407
407
{
408
408
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
409
409
if (Grammar::stringEndsWith (up->getSection (), " {" )) // Found the start of the tag!
@@ -438,7 +438,7 @@ void Grammar::parseUnaryOperators(const vector<Expansion *> & expansions, vector
438
438
}
439
439
else // Looking for a expansion that is taggable
440
440
{
441
- if (!((*expansionIterator)-> getType () == PLUS_OPERATOR || (*expansionIterator)-> getType () == KLEENE_STAR || (*expansionIterator)-> getType () == UNPARSED_SECTION ))
441
+ if (!(EXPANSION_IS_PLUS_OPERATOR (*expansionIterator) || EXPANSION_IS_KLEENE_STAR (*expansionIterator) || EXPANSION_IS_UNPARSED_SECTION (*expansionIterator)))
442
442
{
443
443
foundLegalExpansion = true ; // Found a taggable expansion, select it and start searching for tags
444
444
selectedExpansion = *expansionIterator;
@@ -472,7 +472,7 @@ void Grammar::parseOptionalGroupings(const vector<Expansion *> & expansions, vec
472
472
vector<Expansion *>::iterator expansionIterator = exp .begin ();
473
473
while (expansionIterator != exp .end ())
474
474
{
475
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
475
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
476
476
{
477
477
478
478
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
@@ -584,7 +584,7 @@ void Grammar::parseRequiredGroupings(const vector<Expansion *> & expansions, vec
584
584
vector<Expansion *>::iterator expansionIterator = exp .begin ();
585
585
while (expansionIterator != exp .end ())
586
586
{
587
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
587
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
588
588
{
589
589
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
590
590
string childString;
@@ -713,7 +713,7 @@ void Grammar::parseRuleReferences(const vector<Expansion *> & expansions, vector
713
713
{
714
714
if (startSearch)
715
715
{
716
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
716
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
717
717
{
718
718
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
719
719
if (Grammar::stringEndsWith (up->getSection (), " <" ))
@@ -737,7 +737,7 @@ void Grammar::parseRuleReferences(const vector<Expansion *> & expansions, vector
737
737
}
738
738
else if (endSearch)
739
739
{
740
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
740
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
741
741
{
742
742
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
743
743
if (Grammar::stringStartsWith (up->getSection (), " >" ))
@@ -764,7 +764,7 @@ void Grammar::parseRuleReferences(const vector<Expansion *> & expansions, vector
764
764
}
765
765
else if (tokenSearch)
766
766
{
767
- if ((*expansionIterator)-> getType () == TOKEN )
767
+ if (EXPANSION_IS_TOKEN (*expansionIterator))
768
768
{
769
769
endSearch = true ;
770
770
tokenSearch = false ;
@@ -929,7 +929,7 @@ vector<Expansion *> Grammar::parseTokensFromString(std::string part)
929
929
}
930
930
931
931
bool Grammar::isEmptyUnparsedSection (Expansion * e) {
932
- if (e-> getType () == UNPARSED_SECTION ) {
932
+ if (EXPANSION_IS_UNPARSED_SECTION (e) ) {
933
933
UnparsedSection * u = (UnparsedSection *) e;
934
934
std::string s = u->getSection ();
935
935
if (s.size () == 0 ) {
@@ -973,7 +973,7 @@ Expansion * Grammar::parseAlternativeSets(vector<Expansion *> & exp) {
973
973
974
974
while (expansionIterator != exp .end ())
975
975
{
976
- if ((*expansionIterator)-> getType () == UNPARSED_SECTION )
976
+ if (EXPANSION_IS_UNPARSED_SECTION (*expansionIterator))
977
977
{
978
978
UnparsedSection * up = (UnparsedSection *) *expansionIterator;
979
979
if (Grammar::stringContains (up->getSection (), " |" ))
@@ -1111,7 +1111,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1111
1111
{
1112
1112
vector<shared_ptr<MatchInfo>> matchVector;
1113
1113
1114
- if ((e. get ())-> getType () == TOKEN )
1114
+ if (EXPANSION_IS_TOKEN (e) )
1115
1115
{
1116
1116
Token * t = (Token *) e.get ();
1117
1117
if (t->getText () == (words[wordPosition]))
@@ -1124,7 +1124,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1124
1124
// No match
1125
1125
}
1126
1126
}
1127
- else if ((e. get ())-> getType () == RULE_REFERENCE )
1127
+ else if (EXPANSION_IS_RULE_REFERENCE (e) )
1128
1128
{
1129
1129
RuleReference * ref = (RuleReference *) e.get ();
1130
1130
@@ -1139,7 +1139,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1139
1139
}
1140
1140
}
1141
1141
}
1142
- else if ((e. get ())-> getType () == OPTIONAL_GROUPING )
1142
+ else if (EXPANSION_IS_OPTIONAL_GROUPING (e) )
1143
1143
{
1144
1144
OptionalGrouping * og = (OptionalGrouping *) e.get ();
1145
1145
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (og->getChild (), words, wordCount, wordPosition);
@@ -1155,7 +1155,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1155
1155
matchVector.insert (matchVector.end (), moreMatches.begin (), moreMatches.end ());
1156
1156
}
1157
1157
}
1158
- else if ((e. get ())-> getType () == REQUIRED_GROUPING )
1158
+ else if (EXPANSION_IS_REQUIRED_GROUPING (e) )
1159
1159
{
1160
1160
RequiredGrouping * rg = (RequiredGrouping *) e.get ();
1161
1161
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (rg->getChild (), words, wordCount, wordPosition);
@@ -1166,7 +1166,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1166
1166
matchVector.insert (matchVector.end (), m1.begin (), m1.end ());
1167
1167
}
1168
1168
}
1169
- else if (e. get ()-> getType () == TAG )
1169
+ else if (EXPANSION_IS_TAG (e) )
1170
1170
{
1171
1171
Tag * t = (Tag *) e.get ();
1172
1172
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (t->getChild (), words, wordCount, wordPosition);
@@ -1177,14 +1177,14 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1177
1177
matchVector.insert (matchVector.end (), m1.begin (), m1.end ());
1178
1178
}
1179
1179
}
1180
- else if ((e. get ())-> getType () == ALTERNATE_SET )
1180
+ else if (EXPANSION_IS_ALTERNATE_SET (e) )
1181
1181
{
1182
1182
AlternativeSet * as = (AlternativeSet *) e.get ();
1183
1183
for (shared_ptr<Expansion> x : as->getChildren ())
1184
1184
{
1185
1185
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (x, words, wordCount, wordPosition);
1186
1186
1187
- if (m1.size () == 0 && (x-> getType () == KLEENE_STAR || x-> getType () == OPTIONAL_GROUPING )) // Stupid OptionalGrouping
1187
+ if (m1.size () == 0 && (EXPANSION_IS_KLEENE_STAR (x) || EXPANSION_IS_OPTIONAL_GROUPING (x) )) // Stupid OptionalGrouping
1188
1188
{
1189
1189
continue ;
1190
1190
}
@@ -1197,7 +1197,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1197
1197
}
1198
1198
}
1199
1199
}
1200
- else if ((e. get ())-> getType () == SEQUENCE )
1200
+ else if (EXPANSION_IS_SEQUENCE (e) )
1201
1201
{
1202
1202
Sequence * seq = (Sequence *) e.get ();
1203
1203
vector<shared_ptr<MatchInfo>> localMatchVector;
@@ -1207,7 +1207,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1207
1207
for (shared_ptr<Expansion> x : expansions)
1208
1208
{
1209
1209
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (x, words, wordCount, wordPosition);
1210
- if (m1.size () == 0 && (x-> getType () == KLEENE_STAR || x-> getType () == OPTIONAL_GROUPING )) // Stupid OptionalGrouping
1210
+ if (m1.size () == 0 && (EXPANSION_IS_KLEENE_STAR (x) || EXPANSION_IS_OPTIONAL_GROUPING (x) )) // Stupid OptionalGrouping
1211
1211
{
1212
1212
matchedCount++; // Still counts a match
1213
1213
continue ;
@@ -1237,7 +1237,15 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1237
1237
}
1238
1238
}
1239
1239
1240
- if (matchedCount != seq->childCount ()) // Not all of the required matches were met!
1240
+ unsigned int requiredMatched = 0 ;
1241
+ for (shared_ptr<Expansion> x : expansions) {
1242
+ if (!EXPANSION_IS_OPTIONAL_GROUPING (x) && !EXPANSION_IS_KLEENE_STAR (x)) {
1243
+ requiredMatched++;
1244
+ }
1245
+ }
1246
+
1247
+ // std::cout << "Needed: " << seq->childCount() << " Got: " << matchedCount << std::endl;
1248
+ if (matchedCount < requiredMatched) // Not all of the required matches were met!
1241
1249
{
1242
1250
localMatchVector.clear ();
1243
1251
}
@@ -1248,7 +1256,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1248
1256
matchVector.insert (matchVector.end (), localMatchVector.begin (), localMatchVector.end ());
1249
1257
}
1250
1258
}
1251
- else if ((e. get ()-> getType ()) == KLEENE_STAR )
1259
+ else if (EXPANSION_IS_KLEENE_STAR (e) )
1252
1260
{
1253
1261
KleeneStar * ks = (KleeneStar *) e.get ();
1254
1262
bool done = false ;
@@ -1281,7 +1289,7 @@ vector<shared_ptr<MatchInfo>> Grammar::getMatchingExpansions(shared_ptr<Expansio
1281
1289
}
1282
1290
}
1283
1291
}
1284
- else if ((e. get ())-> getType () == PLUS_OPERATOR )
1292
+ else if (EXPANSION_IS_PLUS_OPERATOR (e) )
1285
1293
{
1286
1294
PlusOperator * po = (PlusOperator *) e.get ();
1287
1295
bool done = false ;
@@ -1331,6 +1339,8 @@ vector<shared_ptr<MatchInfo>> Grammar::matchesRule(const shared_ptr<Rule> rule,
1331
1339
vector<shared_ptr<MatchInfo>> m1 = getMatchingExpansions (rule->getRuleExpansion (), wordArray, words.size (), 0 );
1332
1340
unsigned int matchCount = 0 ;
1333
1341
for (shared_ptr<MatchInfo> mi2 : m1) {
1342
+ // std::cout << "MI: " << mi2->getMatchingSection() << ", " << matchCount << ", " << printExpansionType(mi2->getExpansion().get()) << std::endl;
1343
+
1334
1344
if (mi2->getMatchingSection () != " " ) {
1335
1345
matchCount++;
1336
1346
}
0 commit comments