Skip to content

Commit

Permalink
Merge pull request #48 from librasn/fix/issues-46-47
Browse files Browse the repository at this point in the history
Fix/issues 46 47
  • Loading branch information
6d7a authored Oct 7, 2024
2 parents 4a7285c + 8c598b2 commit d08cc9d
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 16 deletions.
77 changes: 77 additions & 0 deletions rasn-compiler-tests/tests/parameterization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,80 @@ e2e_pdu! {
}
"#
}

e2e_pdu! {
anonymous_type_param,
r#"
SetupRelease { ElementTypeParam } ::= CHOICE {
release NULL,
setup ElementTypeParam
}
LocationMeasurementInfo ::= SEQUENCE {
test BOOLEAN
}
LocationMeasurementIndication-IEs ::= SEQUENCE {
measurementIndication SetupRelease { LocationMeasurementInfo },
lateNonCriticalExtension OCTET STRING OPTIONAL,
nonCriticalExtension SEQUENCE{} OPTIONAL
}
"#,
r#"
#[doc = "Inner type"]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(choice, automatic_tags)]
pub enum LocationMeasurementIndicationIEsMeasurementIndication {
release(()),
setup(LocationMeasurementInfo),
}
#[doc = "Inner type"]
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(automatic_tags)]
pub struct LocationMeasurementIndicationIEsNonCriticalExtension {}
impl LocationMeasurementIndicationIEsNonCriticalExtension {
pub fn new() -> Self {
Self {}
}
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(automatic_tags, identifier = "LocationMeasurementIndication-IEs")]
pub struct LocationMeasurementIndicationIEs {
#[rasn(identifier = "measurementIndication")]
pub measurement_indication: LocationMeasurementIndicationIEsMeasurementIndication,
#[rasn(identifier = "lateNonCriticalExtension")]
pub late_non_critical_extension: Option<OctetString>,
#[rasn(identifier = "nonCriticalExtension")]
pub non_critical_extension: Option<LocationMeasurementIndicationIEsNonCriticalExtension>,
}
impl LocationMeasurementIndicationIEs {
pub fn new(
measurement_indication: LocationMeasurementIndicationIEsMeasurementIndication,
late_non_critical_extension: Option<OctetString>,
non_critical_extension: Option<LocationMeasurementIndicationIEsNonCriticalExtension>,
) -> Self {
Self {
measurement_indication,
late_non_critical_extension,
non_critical_extension,
}
}
}
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(automatic_tags)]
pub struct LocationMeasurementInfo {
pub test: bool,
}
impl LocationMeasurementInfo {
pub fn new(test: bool) -> Self {
Self { test }
}
}
"#
}
2 changes: 1 addition & 1 deletion rasn-compiler-tests/tests/parse_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn compile_etsi() {
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_container.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_ies.asn")
// .add_asn_by_path("../rasn-compiler/test_asn1/ngap_pdus.asn")
.add_asn_by_path("../rasn-compiler/test_asn1/ivi-3.1.asn")
.add_asn_by_path("../rasn-compiler/test_asn1/nr.asn")
.set_output_path("./tests")
.compile()
);
Expand Down
59 changes: 54 additions & 5 deletions rasn-compiler/src/generator/rasn/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,60 @@ impl Rasn {
}
}

const RUST_KEYWORDS: [&'static str; 39] = [
"as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum",
"extern", "false", "final", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod",
"move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super",
"trait", "true", "type", "unsafe", "use", "where", "while",
const RUST_KEYWORDS: [&'static str; 53] = [
"as",
"break",
"const",
"continue",
"crate",
"else",
"enum",
"extern",
"false",
"fn",
"for",
"if",
"impl",
"in",
"let",
"loop",
"match",
"mod",
"move",
"mut",
"pub",
"ref",
"return",
"self",
"Self",
"static",
"struct",
"super",
"trait",
"true",
"type",
"unsafe",
"use",
"where",
"while",
"async",
"await",
"dyn",
"abstract",
"become",
"box",
"do",
"final",
"macro",
"override",
"priv",
"typeof",
"unsized",
"virtual",
"yield",
"try",
"union",
"macro_rules",
];

pub(crate) fn to_rust_snake_case(&self, input: &str) -> Ident {
Expand Down
10 changes: 8 additions & 2 deletions rasn-compiler/src/lexer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ impl<'a> From<nom::Err<nom::error::Error<&'a str>>> for LexerError {
kind: LexerErrorType::NotEnoughData,
},
nom::Err::Error(e) => Self {
details: "Error matching ASN syntax while parsing:".to_owned() + e.input,
details: format!(
"Error matching ASN syntax at while parsing: {}",
&e.input[..(e.input.len().min(300))]
),
kind: LexerErrorType::MatchingError(e.code),
},
nom::Err::Failure(e) => Self {
details: "Unrecoverable error while parsing:".to_owned() + e.input,
details: format!(
"Unrecoverable error while parsing: {}",
&e.input[..(e.input.len().min(300))]
),
kind: LexerErrorType::Failure(e.code),
},
}
Expand Down
1 change: 1 addition & 0 deletions rasn-compiler/src/lexer/parameterization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn parameterization(input: &str) -> IResult<&str, Parameterization> {
skip_ws_and_comments(char(COLON)),
skip_ws_and_comments(identifier),
))),
into(skip_ws_and_comments(identifier)),
))),
)))(input)
}
Expand Down
22 changes: 20 additions & 2 deletions rasn-compiler/src/lexer/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,26 @@ fn parses_choice() {

#[test]
fn parses_sequence_of_value() {
println!(
"{:?}",
assert_eq!(
ToplevelValueDefinition {
comments: "".into(),
name: "test-Sequence".into(),
associated_type: ASN1Type::SequenceOf(SequenceOrSetOf {
constraints: vec![],
element_type: Box::new(ASN1Type::Integer(Integer {
constraints: vec![],
distinguished_values: None
})),
is_recursive: false
}),
parameterization: None,
value: ASN1Value::SequenceOrSet(vec![
(None, Box::new(ASN1Value::Integer(1))),
(None, Box::new(ASN1Value::Integer(2))),
(None, Box::new(ASN1Value::Integer(3)))
]),
index: None
},
top_level_value_declaration(r#"test-Sequence SEQUENCE OF INTEGER ::= { 1, 2, 3 }"#)
.unwrap()
.1
Expand Down
24 changes: 18 additions & 6 deletions rasn-compiler/src/validator/linking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,15 @@ impl ASN1Type {
ASN1Type::Choice(choice) => {
let mut children = Vec::new();
for option in &mut choice.options {
if option.ty.as_str() == name {
option.is_recursive = true;
continue;
match &option.ty {
ASN1Type::ElsewhereDeclaredType(DeclarationElsewhere {
identifier,
..
}) if identifier == name => {
option.is_recursive = true;
continue;
}
_ => (),
}
let opt_ty_name = option.ty.as_str().into_owned();
let mut opt_children = option.ty.mark_recursive(&opt_ty_name)?;
Expand All @@ -575,9 +581,15 @@ impl ASN1Type {
ASN1Type::Set(s) | ASN1Type::Sequence(s) => {
let mut children = Vec::new();
for member in &mut s.members {
if member.ty.as_str() == name {
member.is_recursive = true;
continue;
match &member.ty {
ASN1Type::ElsewhereDeclaredType(DeclarationElsewhere {
identifier,
..
}) if identifier == name => {
member.is_recursive = true;
continue;
}
_ => (),
}
let mem_ty_name = member.ty.as_str().into_owned();
let mut mem_children = member.ty.mark_recursive(&mem_ty_name)?;
Expand Down

0 comments on commit d08cc9d

Please sign in to comment.