Skip to content

Commit 3690955

Browse files
committed
Upgraded to latest Rust version and dependencies
1 parent 4100571 commit 3690955

6 files changed

Lines changed: 100 additions & 109 deletions

File tree

‎Cargo.toml‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "unrealscriptplus"
33
version = "0.2.1"
4-
edition = "2021"
4+
edition = "2024"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

@@ -11,17 +11,17 @@ name = "unrealscriptplus"
1111
crate-type = ["lib", "cdylib"]
1212

1313
[dependencies]
14-
pest = "2.1.3"
15-
pest_derive = "2.1.0"
16-
lazy_static = "1.4.0"
14+
pest = "2.7"
15+
pest_derive = "2.7"
16+
lazy_static = "1.5"
1717
encoding = "0.2"
18-
strum = { version = "0.22", features = ["derive"] }
19-
strum_macros = "0.22"
20-
pest_consume = "1.1.1"
21-
pest_consume_macros = "1.1.0"
22-
convert_case = "0.4.0"
23-
if_chain = "1.0.2"
18+
strum = { version = "0.26", features = ["derive"] }
19+
strum_macros = "0.26"
20+
pest_consume = "1.1"
21+
pest_consume_macros = "1.1"
22+
convert_case = "0.6"
23+
if_chain = "1.0"
2424

2525
[dependencies.pyo3]
26-
version = "0.14.1"
26+
version = "0.27"
2727
features = ["extension-module"]

‎src/lib.rs‎

Lines changed: 83 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,104 @@ pub mod parser;
44
pub mod visitor;
55
pub mod transform;
66

7-
extern crate encoding;
8-
#[macro_use]
9-
extern crate lazy_static;
10-
extern crate pest;
11-
extern crate pest_derive;
12-
137
use pest::error::{ErrorVariant, LineColLocation, InputLocation};
14-
use pest_consume;
158
use crate::parser::{ParsingError, ParserRule, ProgramResult};
169

1710
// PYTHON STUFF
18-
use pyo3::prelude::{pymodule};
11+
use pyo3::prelude::*;
1912
use pyo3::{create_exception, PyErr};
20-
use pyo3::types::{PyDict};
21-
use pyo3::{Python, PyResult, exceptions, PyNativeType, ToPyObject, PyObject};
22-
use pyo3::prelude::PyModule;
13+
use pyo3::types::PyDict;
14+
use pyo3::exceptions;
2315

2416
create_exception!(unrealscriptplus, ScriptParseError, pyo3::exceptions::PyException);
2517

26-
#[pymodule]
27-
fn unrealscriptplus(py: Python, m: &PyModule) -> PyResult<()> {
28-
29-
fn parsing_error_to_py_err(module: &PyModule, error: ParsingError) -> PyErr {
30-
match error {
31-
ParsingError::PestError(e) => ScriptParseError::new_err(pest_error_to_py_object(module.py(), e)),
32-
ParsingError::EncodingError(e) => exceptions::PyUnicodeEncodeError::new_err(e.to_string()),
33-
ParsingError::IoError(e) => exceptions::PyIOError::new_err(e.to_string())
34-
}
35-
}
36-
37-
fn program_result_to_py_object(py: Python, result: &ProgramResult) -> PyObject {
38-
let sequence = vec![
39-
(
40-
"errors".to_object(py),
41-
result.errors.iter().map(|e| {
42-
PyDict::from_sequence(py, vec![
43-
("line".to_object(py), e.span.line.to_object(py)).to_object(py),
44-
("message".to_object(py), e.message.to_object(py)).to_object(py),
45-
("severity".to_object(py), format!("{:?}", e.severity).to_string().to_object(py)).to_object(py),
46-
].to_object(py)).unwrap().to_object(py)
47-
}).collect::<Vec<PyObject>>().to_object(py),
48-
)
49-
].to_object(py);
50-
PyDict::from_sequence(py,sequence).unwrap().to_object(py)
18+
fn parsing_error_to_py_err(py: Python, error: ParsingError) -> PyErr {
19+
match error {
20+
ParsingError::PestError(e) => ScriptParseError::new_err(pest_error_to_py_object(py, e)),
21+
ParsingError::EncodingError(e) => exceptions::PyUnicodeEncodeError::new_err(e.to_string()),
22+
ParsingError::IoError(e) => exceptions::PyIOError::new_err(e.to_string())
5123
}
24+
}
5225

53-
fn pest_error_to_py_object(py: Python, e: pest_consume::Error<ParserRule>) -> PyObject {
54-
let sequence = vec![
55-
(
56-
"line_col".to_object(py),
57-
match e.line_col {
58-
LineColLocation::Pos(pos) => pos.to_object(py),
59-
LineColLocation::Span(span1, span2) => (span1, span2).to_object(py)
60-
}
61-
).to_object(py),
62-
(
63-
"location".to_object(py),
64-
match e.location {
65-
InputLocation::Pos(pos) => pos.to_object(py),
66-
InputLocation::Span(span) => span.to_object(py)
67-
}
68-
).to_object(py),
69-
(
70-
"variant".to_object(py),
71-
match e.variant {
72-
ErrorVariant::ParsingError { positives, negatives } => {
73-
let positives: Vec<String> = positives.into_iter().map(|r| format!("{:?}", r).to_string()).collect();
74-
let negatives: Vec<String> = negatives .into_iter().map(|r| format!("{:?}", r).to_string()).collect();
75-
PyDict::from_sequence(py, vec![
76-
("type".to_object(py), "parsing".to_object(py)).to_object(py),
77-
("positives".to_object(py), positives.to_object(py)).to_object(py),
78-
("negatives".to_object(py), negatives.to_object(py)).to_object(py),
79-
].to_object(py)).unwrap().to_object(py)
80-
},
81-
ErrorVariant::CustomError { message } => {
82-
PyDict::from_sequence(py, vec![
83-
("type".to_object(py), "custom".to_object(py)).to_object(py),
84-
("message".to_object(py), message.to_object(py)).to_object(py)
85-
].to_object(py)).unwrap().to_object(py)
86-
},
87-
}
88-
).to_object(py)
89-
].to_object(py);
90-
PyDict::from_sequence(py, sequence).unwrap().to_object(py)
91-
}
26+
fn program_result_to_py_object(py: Python, result: &ProgramResult) -> Py<PyAny> {
27+
let errors: Vec<Py<PyAny>> = result.errors.iter().map(|e| {
28+
let dict = PyDict::new(py);
29+
dict.set_item("line", e.span.line).unwrap();
30+
dict.set_item("message", &e.message).unwrap();
31+
dict.set_item("severity", format!("{:?}", e.severity)).unwrap();
32+
dict.into()
33+
}).collect();
34+
35+
let dict = PyDict::new(py);
36+
dict.set_item("errors", errors).unwrap();
37+
dict.into()
38+
}
9239

93-
#[pyfn(m)]
94-
#[pyo3(pass_module)]
95-
fn parse_expression(module: &PyModule, path: &str) -> PyResult<String> {
96-
match crate::parser::parse_expression(path) {
97-
Ok(p) => { Ok(format!("{:?}", p)) }
98-
Err(e) => { Err(parsing_error_to_py_err(module, e.into())) }
40+
fn pest_error_to_py_object(py: Python, e: pest_consume::Error<ParserRule>) -> Py<PyAny> {
41+
let dict = PyDict::new(py);
42+
43+
match e.line_col {
44+
LineColLocation::Pos(pos) => {
45+
dict.set_item("line_col", pos).unwrap();
46+
},
47+
LineColLocation::Span(span1, span2) => {
48+
dict.set_item("line_col", (span1, span2)).unwrap();
49+
}
50+
};
51+
52+
match e.location {
53+
InputLocation::Pos(pos) => {
54+
dict.set_item("location", pos).unwrap();
55+
},
56+
InputLocation::Span(span) => {
57+
dict.set_item("location", span).unwrap();
9958
}
59+
};
60+
61+
let variant: Py<PyAny> = match e.variant {
62+
ErrorVariant::ParsingError { positives, negatives } => {
63+
let positives: Vec<String> = positives.into_iter().map(|r| format!("{:?}", r)).collect();
64+
let negatives: Vec<String> = negatives.into_iter().map(|r| format!("{:?}", r)).collect();
65+
let variant_dict = PyDict::new(py);
66+
variant_dict.set_item("type", "parsing").unwrap();
67+
variant_dict.set_item("positives", positives).unwrap();
68+
variant_dict.set_item("negatives", negatives).unwrap();
69+
variant_dict.into()
70+
},
71+
ErrorVariant::CustomError { message } => {
72+
let variant_dict = PyDict::new(py);
73+
variant_dict.set_item("type", "custom").unwrap();
74+
variant_dict.set_item("message", message).unwrap();
75+
variant_dict.into()
76+
},
77+
};
78+
dict.set_item("variant", variant).unwrap();
79+
80+
dict.into()
81+
}
82+
83+
#[pyfunction]
84+
fn parse_expression(py: Python, path: &str) -> PyResult<String> {
85+
match crate::parser::parse_expression(path) {
86+
Ok(p) => { Ok(format!("{:?}", p)) }
87+
Err(e) => { Err(parsing_error_to_py_err(py, e.into())) }
10088
}
89+
}
10190

102-
#[pyfn(m)]
103-
#[pyo3(pass_module)]
104-
fn parse_file(module: &PyModule, path: &str) -> PyResult<PyObject> {
105-
match crate::parser::parse_file(path) {
106-
Ok(result) => {
107-
Ok(program_result_to_py_object(module.py(), &result))
108-
}
109-
Err(e) => Err(parsing_error_to_py_err(module, e))
91+
#[pyfunction]
92+
fn parse_file(py: Python, path: &str) -> PyResult<Py<PyAny>> {
93+
match crate::parser::parse_file(path) {
94+
Ok(result) => {
95+
Ok(program_result_to_py_object(py, &result))
11096
}
97+
Err(e) => Err(parsing_error_to_py_err(py, e))
11198
}
112-
m.add("ScriptParseError", py.get_type::<ScriptParseError>())?;
99+
}
100+
101+
#[pymodule]
102+
fn unrealscriptplus(m: &Bound<'_, PyModule>) -> PyResult<()> {
103+
m.add_function(wrap_pyfunction!(parse_expression, m)?)?;
104+
m.add_function(wrap_pyfunction!(parse_file, m)?)?;
105+
m.add("ScriptParseError", m.py().get_type::<ScriptParseError>())?;
113106
Ok(())
114107
}

‎src/parser.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
extern crate pest;
2-
extern crate if_chain;
3-
41
use pest_consume::Parser;
52

63
#[derive(Parser)]
@@ -10,6 +7,7 @@ pub struct UnrealScriptParser;
107
use pest_consume::{Error, match_nodes};
118
use std::str::FromStr;
129
use std::collections::HashMap;
10+
use lazy_static::lazy_static;
1311

1412
use encoding::{DecoderTrap, Encoding};
1513
use std::fs::File;

‎src/test.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
mod test {
33
use pest::{parses_to, consumes_to, fails_with};
44
use crate::parser::{UnrealScriptParser, Rule};
5-
use crate::transform::{ScriptBuilder, ScriptFormattingOptions};
65

76
#[test]
87
fn comment_single_line() {

‎src/transform.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct ScriptLine {
1010
}
1111

1212
pub struct ScriptBuilder {
13+
#[allow(dead_code)]
1314
options: ScriptFormattingOptions,
1415
indentation: usize,
1516
lines: Vec<ScriptLine>,
@@ -85,8 +86,8 @@ pub trait ToScript {
8586
}
8687

8788
impl ToScript for Program {
88-
fn to_script(&self, builder: &mut ScriptBuilder) {
89-
for statement in &self.statements {
89+
fn to_script(&self, _builder: &mut ScriptBuilder) {
90+
for _statement in &self.statements {
9091
}
9192
}
9293
}
@@ -139,7 +140,7 @@ impl ToScript for ClassModifier {
139140
}
140141

141142
impl ToScript for ExpressionList {
142-
fn to_script(&self, builder: &mut ScriptBuilder) {
143+
fn to_script(&self, _builder: &mut ScriptBuilder) {
143144
todo!()
144145
}
145146
}

‎src/visitor.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct Visitor<'a> {
4747
}
4848

4949
impl Visitor<'_> {
50-
pub fn new(contents: &str) -> Visitor {
50+
pub fn new(contents: &str) -> Visitor<'_> {
5151
Visitor {
5252
contents,
5353
errors: vec![],

0 commit comments

Comments
 (0)