ruff_python_parser/parser/
options.rs1use ruff_python_ast::{PySourceType, PythonVersion};
2
3use crate::{AsMode, Mode};
4
5#[derive(Clone, Debug)]
24pub struct ParseOptions {
25 pub(crate) mode: Mode,
27 pub(crate) target_version: PythonVersion,
29}
30
31impl ParseOptions {
32 #[must_use]
33 pub fn with_target_version(mut self, target_version: PythonVersion) -> Self {
34 self.target_version = target_version;
35 self
36 }
37
38 pub fn target_version(&self) -> PythonVersion {
39 self.target_version
40 }
41}
42
43impl From<Mode> for ParseOptions {
44 fn from(mode: Mode) -> Self {
45 Self {
46 mode,
47 target_version: PythonVersion::default(),
48 }
49 }
50}
51
52impl From<PySourceType> for ParseOptions {
53 fn from(source_type: PySourceType) -> Self {
54 Self {
55 mode: source_type.as_mode(),
56 target_version: PythonVersion::default(),
57 }
58 }
59}