dprint("Participle: {$participle}"); $state = ST_GERUND; break; case ST_GERUND: assert(matchRegexp(REG_GERUND)); $gerund = $matches[1][0]; dprint("Gerund: {$gerund}"); $state = ST_PARTICIPLE_MODEL; break; case ST_PARTICIPLE_MODEL: // This is a bit tricky since the participle model is optional. // If that is the case, we will either have a match from a future model // or no match at all. $futureModel = testRegexp(REG_MODEL_NUMBER); $startFutureModel = $futureModel ? $matches[0][1] : 0; $someClause = testRegexp(REG_PARTICIPLE_MODEL); $startClause = $someClause ? $matches[0][1] : 0; if ($someClause && (!$futureModel || $startClause < $startFutureModel)) { $participleModel = $matches[1][0]; $pos = $matches[0][1] + strlen($matches[0][0]); dprint("Participle model: {$participleModel}"); } else { // The default model is A2. $participleModel = 2; } $state = ST_TENSE_NAMES; break; case ST_TENSE_NAMES: do { $cells = captureTr(); } while (!count($cells));
/** * Captures the next table row and returns an array of the cell values. * Returns null if there are no more <tr> tags. */ function captureTr() { global $matches; global $pos; if (!matchRegexp(REG_TR_OPEN)) { return null; } testRegexp(REG_TR_CLOSE); $closePos = $matches[0][1] + strlen($matches[0][0]); $result = array(); $done = false; do { $anyTd = testRegexp(REG_TD); $startTd = $anyTd ? $matches[0][1] : 0; if (!$anyTd || $startTd > $closePos) { $done = true; } else { $contents = trim($matches[1][0]); if ($contents) { $result[] = $contents; } $pos = $matches[0][1] + strlen($matches[0][0]); } } while (!$done); $pos = $closePos; return $result; }