Skip to content

Commit

Permalink
Rename class
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 19, 2024
1 parent d6a8e3e commit e64c0f0
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion batch/makedist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ src/searchexample.php
src/searchexpr.php
src/searchoperator.php
src/searchoperatorset.php
src/searchparser.php
src/searchselection.php
src/searchsplitter.php
src/searchterm.php
src/searchviewcommand.php
src/searchword.php
Expand Down
4 changes: 2 additions & 2 deletions batch/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ function __construct(Contact $user, $arg) {
$this->diff = isset($arg["diff"]);
$filter = $exclude = null;
foreach ($arg["filter"] ?? [] as $s) {
$ss = new SearchSplitter($s);
$ss = new SearchParser($s);
if (($expr = $ss->parse_expression(SearchOperatorSet::simple_operators()))) {
$filter = $filter ? SearchExpr::combine("or", $filter, $expr) : $expr;
}
}
foreach ($arg["exclude"] ?? [] as $s) {
$ss = new SearchSplitter($s);
$ss = new SearchParser($s);
if (($expr = $ss->parse_expression(SearchOperatorSet::simple_operators()))) {
$exclude = $exclude ? SearchExpr::combine("or", $exclude, $expr) : $expr;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static function _check_conditional_at($s, $p, $len) {
return null;
}
if ($s[$xp] === "(") {
$yp = SearchSplitter::span_balanced_parens($s, $xp + 1) + 1;
$yp = SearchParser::span_balanced_parens($s, $xp + 1) + 1;
if ($yp >= $len || $s[$yp - 1] !== ")") {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assigners/a_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state)
if ($tag === "") {
break;
}
$span = SearchSplitter::span_balanced_parens($tag, 0, " \n\r\t\v\f,;");
$span = SearchParser::span_balanced_parens($tag, 0, " \n\r\t\v\f,;");
$ok = $this->apply1(substr($tag, 0, $span), $prow, $contact, $req, $state)
&& $ok;
$tag = substr($tag, $span);
Expand Down
2 changes: 1 addition & 1 deletion src/formula.php
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ private static function span_parens_until($t, $span) {
$pos = 0;
$len = strlen($t);
while ($pos !== $len && strpos($span, $t[$pos]) === false) {
$x = SearchSplitter::span_balanced_parens($t, $pos, $span, true);
$x = SearchParser::span_balanced_parens($t, $pos, $span, true);
$pos = max($pos + 1, $x);
}
return $pos;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/p_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function add_search_clause($query, $field) {

private function add_user_clause() {
$ids = [];
$accts = new SearchSplitter($this->qreq->u);
$accts = new SearchParser($this->qreq->u);
while (($word = $accts->shift_balanced_parens()) !== "") {
$flags = ContactSearch::F_TAG | ContactSearch::F_USER | ContactSearch::F_ALLOW_DELETED;
if (substr($word, 0, 1) === "\"") {
Expand Down
2 changes: 1 addition & 1 deletion src/paperlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private function _add_sorter($k, $origin, $decorations,
/** @param ?string $str
* @param 0|1|2|3|4|5 $origin */
function parse_view($str, $origin) {
$groups = SearchSplitter::split_balanced_parens($str ?? "");
$groups = SearchParser::split_balanced_parens($str ?? "");
foreach (SearchViewCommand::analyze($groups) as $sve) {
if (($show_action = $sve->show_action())) {
$this->set_view($sve->keyword, $show_action, $origin, $sve->decorations);
Expand Down
10 changes: 5 additions & 5 deletions src/papersearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ private function _search_word($kw, $sword, $scope) {
/** @param string $str
* @return string */
static function escape_word($str) {
$pos = SearchSplitter::span_balanced_parens($str, 0, null, true);
$pos = SearchParser::span_balanced_parens($str, 0, null, true);
if ($pos === strlen($str)) {
return $str;
} else {
Expand Down Expand Up @@ -750,7 +750,7 @@ private function _search_expression($str, $scope = null, $depth = 0) {
return null;
}
$scope = $scope ?? new SearchScope(0, strlen($str), null);
$splitter = new SearchSplitter($str, $scope->pos1, $scope->pos2);
$splitter = new SearchParser($str, $scope->pos1, $scope->pos2);
return $this->_parse_atom($splitter->parse_expression(), $str, $scope, $depth);
}

Expand Down Expand Up @@ -839,7 +839,7 @@ static private function _canonical_expression($str, $type, $qt, Conf $conf, $dep
if ($depth >= 512) {
return "";
}
$splitter = new SearchSplitter($str);
$splitter = new SearchParser($str);
$sa = $splitter->parse_expression(null, $type === "all" ? "SPACE" : "SPACEOR");
if ($type === "none" && $sa) {
$sa = SearchExpr::combine("not", $sa);
Expand Down Expand Up @@ -1179,7 +1179,7 @@ private static function strip_show_atom($a, $top) {
/** @param string $q
* @return string */
private static function strip_show($q) {
$splitter = new SearchSplitter($q, 0, strlen($q));
$splitter = new SearchParser($q, 0, strlen($q));
$span = self::strip_show_atom($splitter->parse_expression(), true);
return $span[0] < $span[1] ? substr($q, $span[0], $span[1] - $span[0]) : "";
}
Expand Down Expand Up @@ -1272,7 +1272,7 @@ static function unparse_view($action, $keyword, $decorations) {
$action = $action ? "show" : "hide";
}
if (!ctype_alnum($keyword)
&& SearchSplitter::span_balanced_parens($keyword) !== strlen($keyword)) {
&& SearchParser::span_balanced_parens($keyword) !== strlen($keyword)) {
$keyword = "\"" . $keyword . "\"";
}
if ($decorations) {
Expand Down
2 changes: 1 addition & 1 deletion src/reviewform.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function highlighted_main_scores() {
return $f ? [$f] : [];
}
$fs = [];
foreach (SearchViewCommand::analyze(SearchSplitter::split_balanced_parens($s)) as $sve) {
foreach (SearchViewCommand::analyze(SearchParser::split_balanced_parens($s)) as $sve) {
if ($sve->show_action() === "show"
&& ($x = $this->conf->find_all_fields($sve->keyword))
&& count($x) === 1
Expand Down
2 changes: 1 addition & 1 deletion src/search/st_review.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static function split($s) {
$cs = [];
$pos = 0;
while ($pos < strlen($s)) {
$pos1 = SearchSplitter::span_balanced_parens($s, $pos, ":", true);
$pos1 = SearchParser::span_balanced_parens($s, $pos, ":", true);
$x = trim(substr($s, $pos, $pos1 - $pos));
if ($x !== ""
&& ctype_digit($x[strlen($x) - 1])
Expand Down
8 changes: 5 additions & 3 deletions src/searchsplitter.php → src/searchparser.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
// searchsplitter.php -- HotCRP helper class for splitting search strings
// searchparser.php -- HotCRP helper class for splitting search strings
// Copyright (c) 2006-2024 Eddie Kohler; see LICENSE.

class SearchSplitter {
class SearchParser {
/** @var string */
private $str;
/** @var bool */
Expand Down Expand Up @@ -192,7 +192,7 @@ static function span_balanced_parens($str, $pos = 0, $endchars = null, $allow_em
static function split_balanced_parens($s) {
$w = [];
if ($s !== "") {
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
while ($splitter->skip_whitespace()) {
$w[] = $splitter->shift_balanced_parens();
}
Expand Down Expand Up @@ -266,3 +266,5 @@ function parse_expression($opset = null, $spaceop = "SPACE", $max_ops = 2048) {
return $cura;
}
}

class_alias("SearchParser", "SearchSplitter"); // XXX compat
2 changes: 1 addition & 1 deletion src/searchviewcommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function complete() {
}

if ($d !== "") {
$splitter = new SearchSplitter($d);
$splitter = new SearchParser($d);
while ($splitter->skip_span(" \n\r\t\v\f,")) {
$this->decorations[] = $splitter->shift_balanced_parens(" \n\r\t\v\f,");
}
Expand Down
2 changes: 1 addition & 1 deletion src/si.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function _expand_pattern($s, $sv) {
while ($p0 < $l && ($p1 = strpos($s, '$', $p0)) !== false) {
$n = strspn($s, '$', $p1);
if ($n === 1 && $p1 + 1 < $l && $s[$p1 + 1] === "{") {
$rb = SearchSplitter::span_balanced_parens($s, $p1 + 2, "", true);
$rb = SearchParser::span_balanced_parens($s, $p1 + 2, "", true);
if ($sv
&& $rb < $l
&& $s[$rb] === "}"
Expand Down
1 change: 1 addition & 0 deletions src/siteloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SiteLoader {
"Present_ReviewFieldSearch" => "src/reviewfieldsearch.php",
"QrequestFile" => "lib/qrequest.php",
"ReviewFieldInfo" => "src/reviewfield.php",
"SearchSplitter" => "src/searchparser.php",
"StreamS3Result" => "lib/s3result.php",
"TagAnno" => "lib/tagger.php",
"TagInfo" => "lib/tagger.php",
Expand Down
10 changes: 5 additions & 5 deletions test/t_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ function test_all() {

function test_search_overflow() {
$s = join(" AND ", array_fill(0, 1024, "a"));
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
xassert_neqq($splitter->parse_expression(null, "SPACE", 1024), null);

$s = join(" AND ", array_fill(0, 1026, "a"));
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
xassert_eqq($splitter->parse_expression(null, "SPACE", 1024), null);

$s = "ti:x";
Expand All @@ -197,17 +197,17 @@ function test_search_overflow() {
/** @suppress PhanTypeArraySuspiciousNullable */
function test_search_splitter_parens() {
$s = "((a) XOR #whatever)";
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
$a = $splitter->parse_expression();
xassert_eqq(json_encode($a->unparse_json()), '{"op":"(","child":[{"op":"xor","child":[{"op":"(","child":["a"]},"#whatever"]}]}');

$s = "(() XOR #whatever)";
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
$a = $splitter->parse_expression();
xassert_eqq(json_encode($a->unparse_json()), '{"op":"(","child":[{"op":"xor","child":[{"op":"(","child":[""]},"#whatever"]}]}');

$s = "((OveMer:>3 OveMer:<2) or (OveMer:>4 OveMer:<3)) #r2";
$splitter = new SearchSplitter($s);
$splitter = new SearchParser($s);
$a = $splitter->parse_expression();
xassert_eqq($a->op->type, "space");
xassert_eqq($a->child[0]->op->type, "(");
Expand Down
20 changes: 10 additions & 10 deletions test/t_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,16 @@ function test_parse_preference() {
}

function test_span_balanced_parens() {
xassert_eqq(SearchSplitter::span_balanced_parens("abc def"), 3);
xassert_eqq(SearchSplitter::span_balanced_parens("abc() def"), 5);
xassert_eqq(SearchSplitter::span_balanced_parens("abc()def ghi"), 8);
xassert_eqq(SearchSplitter::span_balanced_parens("abc(def g)hi"), 12);
xassert_eqq(SearchSplitter::span_balanced_parens("abc(def g)hi jk"), 12);
xassert_eqq(SearchSplitter::span_balanced_parens("abc(def g)h)i jk"), 11);
xassert_eqq(SearchSplitter::span_balanced_parens("abc(def [g)h)i jk"), 12);
xassert_eqq(SearchSplitter::span_balanced_parens("abc(def sajf"), 12);

$m = SearchSplitter::split_balanced_parens(" a(b) )c");
xassert_eqq(SearchParser::span_balanced_parens("abc def"), 3);
xassert_eqq(SearchParser::span_balanced_parens("abc() def"), 5);
xassert_eqq(SearchParser::span_balanced_parens("abc()def ghi"), 8);
xassert_eqq(SearchParser::span_balanced_parens("abc(def g)hi"), 12);
xassert_eqq(SearchParser::span_balanced_parens("abc(def g)hi jk"), 12);
xassert_eqq(SearchParser::span_balanced_parens("abc(def g)h)i jk"), 11);
xassert_eqq(SearchParser::span_balanced_parens("abc(def [g)h)i jk"), 12);
xassert_eqq(SearchParser::span_balanced_parens("abc(def sajf"), 12);

$m = SearchParser::split_balanced_parens(" a(b) )c");
xassert_array_eqq($m, ["a(b)", ")c"]);
}

Expand Down

0 comments on commit e64c0f0

Please sign in to comment.