function LSM::add
Adds a sequence
Parameters
string $sequence Sequence to add:
Return value
$this
1 call to LSM::add()
- LSM::__construct in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ LSM.php - Class constructor
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ LSM.php, line 55
Class
- LSM
- Longest Sequence Matcher. Utility class used by the scanner to consume the longest sequence of character given a set of allowed characters sequences.
Namespace
Peast\SyntaxCode
public function add($sequence) {
if ($this->handleEncoding) {
$s = Utils::stringToUTF8Array($sequence);
$first = $s[0];
$len = count($s);
}
else {
$first = $sequence[0];
$len = strlen($sequence);
}
if (!isset($this->map[$first])) {
$this->map[$first] = array(
"maxLen" => $len,
"map" => array(
$sequence,
),
);
}
else {
$this->map[$first]["map"][] = $sequence;
$this->map[$first]["maxLen"] = max($this->map[$first]["maxLen"], $len);
}
return $this;
}