///////////////////////////////////////////////////////////////////////////
| 1441 | |
| 1442 | //////////////////////////////////////////////////////////////////////////////// |
| 1443 | void CLI2::insertIDExpr() { |
| 1444 | // Skip completely if no ID/UUID was found. This is because below, '(' and ')' |
| 1445 | // are inserted regardless of list size. |
| 1446 | if (!_id_ranges.size() && !_uuid_list.size()) return; |
| 1447 | |
| 1448 | // Find the *first* occurence of lexer type set/number/uuid, and replace it |
| 1449 | // with a synthesized expression. All other occurences are eaten. |
| 1450 | bool changes = false; |
| 1451 | bool foundID = false; |
| 1452 | std::vector<A2> reconstructed; |
| 1453 | for (const auto& a : _args) { |
| 1454 | if ((a._lextype == Lexer::Type::set || a._lextype == Lexer::Type::number || |
| 1455 | a._lextype == Lexer::Type::uuid) && |
| 1456 | a.hasTag("FILTER")) { |
| 1457 | if (!foundID) { |
| 1458 | foundID = true; |
| 1459 | changes = true; |
| 1460 | |
| 1461 | // Construct a single sequence that represents all _id_ranges and |
| 1462 | // _uuid_list in one clause. This is essentially converting this: |
| 1463 | // |
| 1464 | // 1,2-3 uuid,uuid uuid 4 |
| 1465 | // |
| 1466 | // into: |
| 1467 | // |
| 1468 | // ( |
| 1469 | // ( id == 1 ) |
| 1470 | // or ( ( id >= 2 ) and ( id <= 3 ) ) |
| 1471 | // or ( id == 4 ) |
| 1472 | // or ( uuid = $UUID ) |
| 1473 | // or ( uuid = $UUID ) |
| 1474 | // ) |
| 1475 | |
| 1476 | // Building block operators. |
| 1477 | A2 openParen("(", Lexer::Type::op); |
| 1478 | openParen.tag("FILTER"); |
| 1479 | A2 closeParen(")", Lexer::Type::op); |
| 1480 | closeParen.tag("FILTER"); |
| 1481 | A2 opOr("or", Lexer::Type::op); |
| 1482 | opOr.tag("FILTER"); |
| 1483 | A2 opAnd("and", Lexer::Type::op); |
| 1484 | opAnd.tag("FILTER"); |
| 1485 | A2 opSimilar("=", Lexer::Type::op); |
| 1486 | opSimilar.tag("FILTER"); |
| 1487 | A2 opEqual("==", Lexer::Type::op); |
| 1488 | opEqual.tag("FILTER"); |
| 1489 | A2 opGTE(">=", Lexer::Type::op); |
| 1490 | opGTE.tag("FILTER"); |
| 1491 | A2 opLTE("<=", Lexer::Type::op); |
| 1492 | opLTE.tag("FILTER"); |
| 1493 | |
| 1494 | // Building block attributes. |
| 1495 | A2 argID("id", Lexer::Type::dom); |
| 1496 | argID.tag("FILTER"); |
| 1497 | |
| 1498 | A2 argUUID("uuid", Lexer::Type::dom); |
| 1499 | argUUID.tag("FILTER"); |
| 1500 |