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.
13#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
14#[non_exhaustive]
15pub enum PhpVersion {
16 /// PHP 7.4 — arrow functions, typed properties, spread in array expressions, numeric literal separator.
17 Php74,
18 /// PHP 8.0 — match, named arguments, constructor promotion, union types, nullsafe `?->`, throw expression, `mixed`/`false`/`null` types.
19 Php80,
20 /// PHP 8.1 — enums, `readonly` properties/parameters, intersection types, first-class callables, `never` type.
21 Php81,
22 /// PHP 8.2 — `readonly class` (also `abstract readonly class`), DNF types, `true` type.
23 Php82,
24 /// PHP 8.3 — typed class/enum constants.
25 Php83,
26 /// PHP 8.4 — property hooks, asymmetric visibility.
27 Php84,
28 /// PHP 8.5 — pipe operator (`|>`), `clone` with property overrides, `final` promoted properties,
29 /// asymmetric visibility on static properties.
30 #[default]
31 Php85,
32 /// PHP 8.6 (unreleased) — partial function application (`?`/`...` call-argument placeholders).
33 Php86,
34}
35
36impl fmt::Display for PhpVersion {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self {
39 PhpVersion::Php74 => write!(f, "7.4"),
40 PhpVersion::Php80 => write!(f, "8.0"),
41 PhpVersion::Php81 => write!(f, "8.1"),
42 PhpVersion::Php82 => write!(f, "8.2"),
43 PhpVersion::Php83 => write!(f, "8.3"),
44 PhpVersion::Php84 => write!(f, "8.4"),
45 PhpVersion::Php85 => write!(f, "8.5"),
46 PhpVersion::Php86 => write!(f, "8.6"),
47 }
48 }
49}