public function read_num($prefix = '') { $has_e = false; $after_e = false; $has_x = false; $has_dot = $prefix == '.'; $num = $this->read_while(function ($ch, $i) use(&$has_e, &$after_e, &$has_x, &$has_dot) { if ($ch == 'x' || $ch == 'X') { if ($has_x) { return false; } return $has_x = true; } if (!$has_x && ($ch == 'e' || $ch == 'E')) { if ($has_e) { return false; } return $has_e = $after_e = true; } if ($ch == '-') { if ($after_e || $i == 0 && !$prefix) { return true; } return false; } if ($ch == '+') { return $after_e; } $after_e = false; if ($ch == '.') { if (!$has_dot && !$has_x) { return $has_dot = true; } return false; } return ParseJS::is_alphanumeric_char($ch); }); if ($prefix) { $num = $prefix . $num; } $valid = ParseJS::parse_js_number($num); if (is_numeric($valid)) { return $this->token('num', $valid); } else { return $this->parse_error('Invalid syntax: ' . $num); } }