php_rs_parser/version.rs
1use std::fmt;
2
3/// The PHP language version the parser should target.
4///
5/// When a [`PhpVersion`] is set in [`crate::ParseOptions`], the parser
6/// emits [`crate::diagnostics::ParseError::VersionTooLow`] for any syntax that
7/// requires a higher version. The AST is still produced (the parser recovers),
8/// so callers can always inspect what was parsed.
9///
10/// Ordering is meaningful: `Php82 > Php81`, etc.
11///
12/// Defaults to [`PhpVersion::Php85`], the latest released version — [`PhpVersion::Php86`] must
13/// be opted into explicitly since PHP 8.6 hasn't shipped yet.
14#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
15#[non_exhaustive]
16pub enum PhpVersion {
17 /// PHP 7.4 — arrow functions, typed properties, spread in array expressions, numeric literal separator.
18 Php74,
19 /// PHP 8.0 — match, named arguments, constructor promotion, union types, nullsafe `?->`, throw expression, `mixed`/`false`/`null` types.
20 Php80,
21 /// PHP 8.1 — enums, `readonly` properties/parameters, intersection types, first-class callables, `never` type.
22 Php81,
23 /// PHP 8.2 — `readonly class`, DNF types, `true` type.
24 Php82,
25 /// PHP 8.3 — typed class/enum constants.
26 Php83,
27 /// PHP 8.4 — `abstract readonly class`, property hooks, asymmetric visibility.
28 Php84,
29 /// PHP 8.5 — pipe operator (`|>`), `clone` with property overrides, `final` promoted properties,
30 /// asymmetric visibility on static properties.
31 #[default]
32 Php85,
33 /// PHP 8.6 (unreleased) — partial function application (`?`/`...` call-argument placeholders).
34 Php86,
35}
36
37impl fmt::Display for PhpVersion {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 PhpVersion::Php74 => write!(f, "7.4"),
41 PhpVersion::Php80 => write!(f, "8.0"),
42 PhpVersion::Php81 => write!(f, "8.1"),
43 PhpVersion::Php82 => write!(f, "8.2"),
44 PhpVersion::Php83 => write!(f, "8.3"),
45 PhpVersion::Php84 => write!(f, "8.4"),
46 PhpVersion::Php85 => write!(f, "8.5"),
47 PhpVersion::Php86 => write!(f, "8.6"),
48 }
49 }
50}