Skip to content

Commit 4721541

Browse files
committed
feat: rust reader now only checks json files
1 parent 8049388 commit 4721541

File tree

4 files changed

+122
-164
lines changed

4 files changed

+122
-164
lines changed

cli/src/analyser/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::formatter::{error, warning};
2-
use code0_definition_reader::reader::ParsableDefinition;
32
use std::cmp::PartialEq;
43
use std::path::Path;
54
use std::process::exit;
5+
use code0_definition_reader::reader::Meta;
66

77
#[derive(Default)]
88
pub struct Reporter {
@@ -84,7 +84,7 @@ pub enum Severity {
8484
pub struct Diagnose {
8585
kind: DiagnosticKind,
8686
definition_name: String,
87-
definition: ParsableDefinition,
87+
definition: Meta,
8888
}
8989

9090
pub enum DiagnosticKind {
@@ -127,7 +127,7 @@ impl DiagnosticKind {
127127
impl Diagnose {
128128
pub fn new(
129129
definition_name: String,
130-
definition: ParsableDefinition,
130+
definition: Meta,
131131
kind: DiagnosticKind,
132132
) -> Self {
133133
Self {
@@ -140,8 +140,8 @@ impl Diagnose {
140140
pub fn print(&self) -> String {
141141
let path = format!(
142142
"{}:{}:{}",
143-
Path::new(&self.definition.path.clone().unwrap_or_default()).display(),
144-
&self.definition.starting_line,
143+
Path::new(&self.definition.path.clone()).display(),
144+
1,
145145
1
146146
);
147147

cli/src/analyser/mod.rs

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ use crate::analyser::diagnostics::DiagnosticKind::{
77
};
88
use crate::analyser::diagnostics::{Diagnose, DiagnosticKind, Reporter};
99
use code0_definition_reader::parser::Parser;
10-
use code0_definition_reader::reader::{MetaType, ParsableDefinition, Reader};
10+
use code0_definition_reader::reader::{Meta, MetaType, Reader};
1111
use tucana::shared::data_type_identifier::Type;
1212
use tucana::shared::definition_data_type_rule::Config;
1313
use tucana::shared::{DataTypeIdentifier, DefinitionDataType, FlowType, RuntimeFunctionDefinition};
1414

1515
#[derive(Clone)]
1616
pub struct AnalysableDataType {
17-
pub original_definition: ParsableDefinition,
17+
pub original_definition: Meta,
1818
pub definition_data_type: DefinitionDataType,
1919
pub id: i16,
2020
}
2121

2222
#[derive(Clone)]
2323
pub struct AnalysableFlowType {
24-
pub original_definition: ParsableDefinition,
24+
pub original_definition: Meta,
2525
pub flow_type: FlowType,
2626
pub id: i16,
2727
}
2828

2929
#[derive(Clone)]
3030
pub struct AnalysableFunction {
31-
pub original_definition: ParsableDefinition,
31+
pub original_definition: Meta,
3232
pub function: RuntimeFunctionDefinition,
3333
pub id: i16,
3434
}
@@ -55,89 +55,83 @@ impl Analyser {
5555
let mut collected_flow_types: Vec<AnalysableFlowType> = vec![];
5656
let mut collected_functions: Vec<AnalysableFunction> = vec![];
5757

58-
for features in reader.meta {
59-
match features.r#type {
58+
for definition in reader.meta {
59+
match definition.r#type {
6060
MetaType::FlowType => {
61-
for p_flow_type in &features.data {
62-
current_index += 1;
63-
match serde_json::from_str::<FlowType>(
64-
p_flow_type.definition_string.as_str(),
65-
) {
66-
Ok(flow_type) => collected_flow_types.push(AnalysableFlowType {
67-
original_definition: p_flow_type.clone(),
68-
flow_type,
69-
id: current_index,
70-
}),
71-
Err(err) => {
72-
let name = Parser::extract_identifier(
73-
p_flow_type.definition_string.as_str(),
74-
MetaType::FlowType,
75-
);
76-
let diagnose = Diagnose::new(
77-
name,
78-
p_flow_type.clone(),
79-
DiagnosticKind::DeserializationError {
80-
description: err.to_string(),
81-
},
82-
);
83-
reporter.add_report(diagnose);
84-
}
61+
current_index += 1;
62+
match serde_json::from_str::<FlowType>(
63+
definition.definition_string.as_str(),
64+
) {
65+
Ok(flow_type) => collected_flow_types.push(AnalysableFlowType {
66+
original_definition: definition.clone(),
67+
flow_type,
68+
id: current_index,
69+
}),
70+
Err(err) => {
71+
let name = Parser::extract_identifier(
72+
definition.definition_string.as_str(),
73+
MetaType::FlowType,
74+
);
75+
let diagnose = Diagnose::new(
76+
name,
77+
definition.clone(),
78+
DiagnosticKind::DeserializationError {
79+
description: err.to_string(),
80+
},
81+
);
82+
reporter.add_report(diagnose);
8583
}
8684
}
8785
}
8886
MetaType::DataType => {
89-
for p_data_type in &features.data {
90-
current_index += 1;
91-
match serde_json::from_str::<DefinitionDataType>(
92-
p_data_type.definition_string.as_str(),
93-
) {
94-
Ok(data_type) => collected_data_types.push(AnalysableDataType {
95-
original_definition: p_data_type.clone(),
96-
definition_data_type: data_type,
97-
id: current_index,
98-
}),
99-
Err(err) => {
100-
let name = Parser::extract_identifier(
101-
p_data_type.definition_string.as_str(),
102-
MetaType::DataType,
103-
);
104-
let diagnose = Diagnose::new(
105-
name,
106-
p_data_type.clone(),
107-
DiagnosticKind::DeserializationError {
108-
description: err.to_string(),
109-
},
110-
);
111-
reporter.add_report(diagnose);
112-
}
87+
current_index += 1;
88+
match serde_json::from_str::<DefinitionDataType>(
89+
definition.definition_string.as_str(),
90+
) {
91+
Ok(data_type) => collected_data_types.push(AnalysableDataType {
92+
original_definition: definition.clone(),
93+
definition_data_type: data_type,
94+
id: current_index,
95+
}),
96+
Err(err) => {
97+
let name = Parser::extract_identifier(
98+
definition.definition_string.as_str(),
99+
MetaType::DataType,
100+
);
101+
let diagnose = Diagnose::new(
102+
name,
103+
definition.clone(),
104+
DiagnosticKind::DeserializationError {
105+
description: err.to_string(),
106+
},
107+
);
108+
reporter.add_report(diagnose);
113109
}
114110
}
115111
}
116112
MetaType::RuntimeFunction => {
117-
for p_function in &features.data {
118-
current_index += 1;
119-
match serde_json::from_str::<RuntimeFunctionDefinition>(
120-
p_function.definition_string.as_str(),
121-
) {
122-
Ok(function) => collected_functions.push(AnalysableFunction {
123-
original_definition: p_function.clone(),
124-
function,
125-
id: current_index,
126-
}),
127-
Err(err) => {
128-
let name = Parser::extract_identifier(
129-
p_function.definition_string.as_str(),
130-
MetaType::RuntimeFunction,
131-
);
132-
let diagnose = Diagnose::new(
133-
name,
134-
p_function.clone(),
135-
DiagnosticKind::DeserializationError {
136-
description: err.to_string(),
137-
},
138-
);
139-
reporter.add_report(diagnose);
140-
}
113+
current_index += 1;
114+
match serde_json::from_str::<RuntimeFunctionDefinition>(
115+
definition.definition_string.as_str(),
116+
) {
117+
Ok(function) => collected_functions.push(AnalysableFunction {
118+
original_definition: definition.clone(),
119+
function,
120+
id: current_index,
121+
}),
122+
Err(err) => {
123+
let name = Parser::extract_identifier(
124+
definition.definition_string.as_str(),
125+
MetaType::RuntimeFunction,
126+
);
127+
let diagnose = Diagnose::new(
128+
name,
129+
definition.clone(),
130+
DiagnosticKind::DeserializationError {
131+
description: err.to_string(),
132+
},
133+
);
134+
reporter.add_report(diagnose);
141135
}
142136
}
143137
}
@@ -674,7 +668,7 @@ impl Analyser {
674668
fn handle_function_data_type_identifier(
675669
&mut self,
676670
name: String,
677-
original: ParsableDefinition,
671+
original: Meta,
678672
identifier: DataTypeIdentifier,
679673
) -> Vec<String> {
680674
let mut result: Vec<String> = vec![];

reader/rust/src/parser.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,39 +88,37 @@ impl Parser {
8888
}
8989

9090
fn append_meta(feature: &mut Feature, meta: &crate::reader::Meta) {
91-
for definition in &meta.data {
92-
let definition = definition.definition_string.as_str();
93-
match meta.r#type {
94-
MetaType::DataType => {
95-
match serde_json::from_str::<DefinitionDataType>(definition) {
96-
Ok(data_type) => feature.data_types.push(data_type),
97-
Err(err) => feature.errors.push(DefinitionError {
98-
definition: Parser::extract_identifier(definition, MetaType::DataType),
99-
definition_type: MetaType::DataType,
100-
error: err.to_string(),
101-
}),
102-
}
91+
let definition = meta.definition_string.as_str();
92+
match meta.r#type {
93+
MetaType::DataType => {
94+
match serde_json::from_str::<DefinitionDataType>(definition) {
95+
Ok(data_type) => feature.data_types.push(data_type),
96+
Err(err) => feature.errors.push(DefinitionError {
97+
definition: Parser::extract_identifier(definition, MetaType::DataType),
98+
definition_type: MetaType::DataType,
99+
error: err.to_string(),
100+
}),
103101
}
104-
MetaType::FlowType => match serde_json::from_str::<FlowType>(definition) {
105-
Ok(flow_type) => feature.flow_types.push(flow_type),
102+
}
103+
MetaType::FlowType => match serde_json::from_str::<FlowType>(definition) {
104+
Ok(flow_type) => feature.flow_types.push(flow_type),
105+
Err(err) => feature.errors.push(DefinitionError {
106+
definition: Parser::extract_identifier(definition, MetaType::FlowType),
107+
definition_type: MetaType::FlowType,
108+
error: err.to_string(),
109+
}),
110+
},
111+
MetaType::RuntimeFunction => {
112+
match serde_json::from_str::<RuntimeFunctionDefinition>(definition) {
113+
Ok(func) => feature.runtime_functions.push(func),
106114
Err(err) => feature.errors.push(DefinitionError {
107-
definition: Parser::extract_identifier(definition, MetaType::FlowType),
108-
definition_type: MetaType::FlowType,
115+
definition: Parser::extract_identifier(
116+
definition,
117+
MetaType::RuntimeFunction,
118+
),
119+
definition_type: MetaType::RuntimeFunction,
109120
error: err.to_string(),
110121
}),
111-
},
112-
MetaType::RuntimeFunction => {
113-
match serde_json::from_str::<RuntimeFunctionDefinition>(definition) {
114-
Ok(func) => feature.runtime_functions.push(func),
115-
Err(err) => feature.errors.push(DefinitionError {
116-
definition: Parser::extract_identifier(
117-
definition,
118-
MetaType::RuntimeFunction,
119-
),
120-
definition_type: MetaType::RuntimeFunction,
121-
error: err.to_string(),
122-
}),
123-
}
124122
}
125123
}
126124
}

0 commit comments

Comments
 (0)