Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse RPSL into borrowing ObjectView convertible to owned Object #50

Merged
merged 38 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9a59c66
Refactor of entire codebase (#43)
SRv6d Nov 20, 2023
cf30033
Replace `Object` with `ObjectView`, containing slices, avoiding alloc…
SRv6d Nov 26, 2023
685ee0e
Use chaining instead of mutable vec
SRv6d Nov 26, 2023
6d07742
Allow module name repetition
SRv6d Nov 26, 2023
bfe93d9
Add doc comments
SRv6d Nov 27, 2023
d2acba2
Simplify `ObjectView` by using newtype
SRv6d Nov 27, 2023
06c2b8d
Add proptest as dev dependency
SRv6d Nov 28, 2023
8e70f62
Add `Name(String)` with validation against RPSL spec
SRv6d Nov 28, 2023
59548c5
Move `coerce_empty_value` to common module
SRv6d Nov 28, 2023
01ca704
Add `Value` with validation against RPSL spec
SRv6d Nov 29, 2023
4ff2f90
Add `Attribute` struct
SRv6d Nov 30, 2023
158c4aa
Add `Object` struct
SRv6d Nov 30, 2023
956256b
Allow `Value` from `Vec` of single `&str`
SRv6d Dec 4, 2023
e0b9a69
Implement `Index` for `Object`
SRv6d Dec 4, 2023
ec01fd4
Add `object!` macro
SRv6d Dec 4, 2023
96061d5
Re add adjusted docstring
SRv6d Dec 4, 2023
a63844b
Implement `Display` for `Object` & `Attribute`
SRv6d Dec 4, 2023
ac2df2e
Implement `PartialEq<&str>` for `Name`
SRv6d Dec 4, 2023
9a268ca
Implement `len` and `IntoIterator` for `Object`
SRv6d Dec 4, 2023
d1883b9
Implement `get` for `Object`
SRv6d Dec 4, 2023
cd2266e
Improve doc comments
SRv6d Dec 7, 2023
25f41a7
Implement `len` for `ValueView`, `ObjectView` & `Value`
SRv6d Dec 7, 2023
1935c89
Implement `IntoIterator` for `Value` & `ValueView`
SRv6d Dec 7, 2023
7b4a2a6
Implement `PartialEq` for owned & borrowed value
SRv6d Dec 7, 2023
9ff05a5
Implement `PartialEq` for `NameView`
SRv6d Dec 7, 2023
7a196e5
Implement `PartialEq` for `Attribute` and `AttributeView`
SRv6d Dec 7, 2023
ff5c1d9
Ack clippy warning
SRv6d Dec 7, 2023
1a5bd86
Implement `PartialEq` for `Object` and `ObjectView`
SRv6d Dec 7, 2023
1bf6715
Add disclaimer
SRv6d Dec 8, 2023
a59c0e9
Update docs
SRv6d Dec 9, 2023
a92caa2
Implement `get` for borrowed object
SRv6d Dec 9, 2023
9f373a0
Add missing `#[cfg(test)]` annotations
SRv6d Dec 9, 2023
f54e252
Implement converting borrowed to owned types
SRv6d Dec 9, 2023
2beb599
Add initegration tests for RPSL display
SRv6d Dec 9, 2023
a701824
Implement `Display` for `AttributeView`
SRv6d Dec 9, 2023
86c1d5a
Exclude source from `ObjectView` `Debug`
SRv6d Dec 9, 2023
f46fdc9
Fix typos
SRv6d Dec 9, 2023
4c4f1f6
Merge branch 'main' into view-types
SRv6d Dec 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ thiserror = "1.0.50"
[dev-dependencies]
codspeed-criterion-compat = "2.3.3"
criterion = { version = "0.5.1", features = ["html_reports"] }
proptest = "1.4.0"

[[bench]]
name = "parse_as3257"
Expand Down
12 changes: 6 additions & 6 deletions examples/print_parsed_as3257.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use rpsl_parser::{parse_object, Object};
use rpsl_parser::{parse_object, ObjectView};

fn main() {
let aut_num_gtt: ObjectView = parse_object(AS3257).unwrap();
println!("{:#?}", aut_num_gtt);
}

const AS3257: &str = r#"aut-num: AS3257
as-name: GTT-BACKBONE
Expand Down Expand Up @@ -9569,8 +9574,3 @@ last-modified: 2023-07-21T10:03:34Z
source: RIPE

"#;

fn main() {
let aut_num_gtt: Object = parse_object(AS3257).unwrap();
println!("{:#?}", aut_num_gtt);
}
12 changes: 6 additions & 6 deletions examples/print_parsed_as3257_whois_response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use rpsl_parser::{parse_whois_response, Object};
use rpsl_parser::{parse_whois_response, ObjectView};

fn main() {
let parsed_objects: Vec<ObjectView> = parse_whois_response(AS3257_WHOIS_RESPONSE).unwrap();
println!("{:#?}", parsed_objects);
}

const AS3257_WHOIS_RESPONSE: &str = r#"
% Note: this output has been filtered.
Expand Down Expand Up @@ -9699,8 +9704,3 @@ source: RIPE # Filtered


"#;

fn main() {
let parsed_objects: Vec<Object> = parse_whois_response(AS3257_WHOIS_RESPONSE).unwrap();
println!("{:#?}", parsed_objects);
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

pub use parser::{parse_object, parse_whois_response};
pub use rpsl::error::AttributeError;
pub use rpsl::{Attribute, Object};
pub use rpsl::{Attribute, AttributeView, Object, ObjectView};

mod parser;
mod rpsl;
19 changes: 9 additions & 10 deletions src/parser/component.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::rpsl::Attribute;
use crate::rpsl::AttributeView;
use nom::{
bytes::complete::{tag, take_while},
character::complete::{newline, space0},
Expand All @@ -24,21 +24,21 @@ pub fn server_message(input: &str) -> IResult<&str, &str> {
// A RPSL attribute consisting of a name and one or more values.
// The name is followed by a colon and optional spaces.
// Single value attributes are limited to one line, while multi value attributes span over multiple lines.
pub fn attribute(input: &str) -> IResult<&str, Attribute> {
pub fn attribute(input: &str) -> IResult<&str, AttributeView> {
let (remaining, (name, first_value)) = separated_pair(
terminated(subcomponent::attribute_name, tag(":")),
space0,
terminated(subcomponent::attribute_value, newline),
)(input)?;

if peek(subcomponent::continuation_char)(remaining).is_err() {
Ok((remaining, Attribute::new(name, first_value).unwrap()))
Ok((remaining, AttributeView::new_single(name, first_value)))
} else {
let (remaining, continuation_values) = many0(subcomponent::continuation_line)(remaining)?;
let mut values: Vec<&str> = Vec::with_capacity(1 + continuation_values.len());
values.push(first_value);
values.extend(continuation_values);
Ok((remaining, Attribute::new(name, values).unwrap()))
let values = std::iter::once(first_value)
.chain(continuation_values)
.collect();
Ok((remaining, AttributeView::new_multi(name, values)))
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ mod tests {
attribute("import: from AS12 accept AS12\n"),
Ok((
"",
Attribute::new("import", "from AS12 accept AS12").unwrap()
AttributeView::new_single("import", "from AS12 accept AS12")
))
);
}
Expand All @@ -94,15 +94,14 @@ mod tests {
)),
Ok((
"remarks: Peering Policy\n",
Attribute::new(
AttributeView::new_multi(
"remarks",
vec![
"Locations",
"LA1 - CoreSite One Wilshire",
"NY1 - Equinix New York, Newark",
]
)
.unwrap()
))
);
}
Expand Down
Loading
Loading