-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.rs
More file actions
82 lines (76 loc) · 2.21 KB
/
Copy pathhandler.rs
File metadata and controls
82 lines (76 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pub mod analyser;
pub mod base;
pub mod buffer;
pub mod indenter;
pub mod indexer;
pub mod output;
pub mod python;
pub mod regex;
pub mod replace;
pub mod shorten;
pub mod unstringify;
pub use analyser::AnalyserHandler;
pub use base::BaseHandler;
pub use buffer::BufferHandler;
pub use indenter::IndenterHandler;
pub use indexer::IndexerHandler;
pub use output::{FileHandler, StdoutHandler};
pub use python::PythonHandler;
pub use regex::RegexHandler;
pub use replace::ReplaceHandler;
pub use shorten::ShortenHandler;
pub use unstringify::UnstringifyHandler;
use pyo3::prelude::*;
use streamson_lib::streamer;
#[pyclass]
pub struct PythonParsedKind {
pub kind: String,
}
impl From<streamer::ParsedKind> for PythonParsedKind {
fn from(kind: streamer::ParsedKind) -> Self {
match kind {
streamer::ParsedKind::Obj => Self { kind: "Obj".into() },
streamer::ParsedKind::Arr => Self { kind: "Arr".into() },
streamer::ParsedKind::Str => Self { kind: "Str".into() },
streamer::ParsedKind::Num => Self { kind: "Num".into() },
streamer::ParsedKind::Null => Self {
kind: "Null".into(),
},
streamer::ParsedKind::Bool => Self {
kind: "Bool".into(),
},
}
}
}
#[pyclass]
pub struct PythonToken {
pub token: String,
pub idx: Option<usize>,
pub kind: Option<PythonParsedKind>,
}
impl From<streamer::Token> for PythonToken {
fn from(token: streamer::Token) -> Self {
match token {
streamer::Token::Start(idx, kind) => Self {
token: "Start".into(),
idx: Some(idx),
kind: Some(kind.into()),
},
streamer::Token::End(idx, kind) => Self {
token: "End".into(),
idx: Some(idx),
kind: Some(kind.into()),
},
streamer::Token::Separator(idx) => Self {
token: "Separator".into(),
idx: Some(idx),
kind: None,
},
streamer::Token::Pending => Self {
token: "Pending".into(),
idx: None,
kind: None,
},
}
}
}