< >= <= >> << >>> <<< >>= <<= && | || ! !! , : ? ^ ^= |='); $n_newlines = 0; do { if ($pos >= $input_length) { return array('', TK_EOF); } $c = $input[$pos]; $pos += 1; if ($c == "\n") { $n_newlines += 1; } } while (in_array($c, $whitespace)); if ($n_newlines) { safe_nl($n_newlines); } if (in_array($c, $wordchar)) { if ($pos < $input_length) { while (in_array($input[$pos], $wordchar)) { $c .= $input[$pos]; $pos += 1; if ($pos == $input_length) break; } } if ($c == 'in') { // hack for 'in' operator return array($c, TK_OPERATOR); } return array($c, TK_WORD); } if ($c == '(' || $c == '[') { return array($c, TK_START_EXPR); } if ($c == ')' || $c == ']') { return array($c, TK_END_EXPR); } if ($c == '{') { return array($c, TK_START_BLOCK); } if ($c == '}') { return array($c, TK_END_BLOCK); } if ($c == ';') { return array($c, TK_END_COMMAND); } if ($c == '/') { // peek for comment /* ... */ if ($input[$pos] == '*') { $comment = ''; $pos += 1; if ($pos < $input_length){ while (!($input[$pos] == '*' && isset($input[$pos + 1]) && $input[$pos + 1] == '/') && $pos < $input_length) { $comment .= $input[$pos]; $pos += 1; if ($pos >= $input_length) break; } } $pos +=2; return array("/*$comment*/", TK_BLOCK_COMMENT); } // peek for comment // ... if ($input[$pos] == '/') { $comment = $c; while ($input[$pos] != "\x0d" && $input[$pos] != "\x0a") { $comment .= $input[$pos]; $pos += 1; if ($pos >= $input_length) break; } $pos += 1; return array($comment, TK_COMMENT); } } if ($c == "'" || // string $c == '"' || // string ($c == '/' && (($last_type == TK_WORD and $last_text == 'return') or ($last_type == TK_START_EXPR || $last_type == TK_END_BLOCK || $last_type == TK_OPERATOR || $last_type == TK_EOF || $last_type == TK_END_COMMAND)))) { // regexp $sep = $c; $c = ''; $esc = false; if ($pos < $input_length) { while ($esc || $input[$pos] != $sep) { $c .= $input[$pos]; if (!$esc) { $esc = $input[$pos] == '\\'; } else { $esc = false; } $pos += 1; if ($pos >= $input_length) break; } } $pos += 1; if ($last_type == TK_END_COMMAND) { nl(); } return array($sep . $c . $sep, TK_STRING); } if (in_array($c, $punct)) { while (in_array($c . $input[$pos], $punct)) { $c .= $input[$pos]; $pos += 1; if ($pos >= $input_length) break; } return array($c, TK_OPERATOR); } return array($c, TK_UNKNOWN); } ?>