Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions rasn-compiler/src/intermediate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ impl ASN1Type {
ASN1Type::SetOf(s) | ASN1Type::SequenceOf(s) => Some(s.constraints()),
ASN1Type::ElsewhereDeclaredType(e) => Some(e.constraints()),
ASN1Type::InformationObjectFieldReference(f) => Some(f.constraints()),
ASN1Type::ObjectIdentifier(o) => Some(&o.constraints),
_ => None,
}
}
Expand All @@ -969,6 +970,7 @@ impl ASN1Type {
ASN1Type::SetOf(s) | ASN1Type::SequenceOf(s) => Some(s.constraints_mut()),
ASN1Type::ElsewhereDeclaredType(e) => Some(e.constraints_mut()),
ASN1Type::InformationObjectFieldReference(f) => Some(f.constraints_mut()),
ASN1Type::ObjectIdentifier(o) => Some(&mut o.constraints),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion rasn-compiler/src/lexer/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn set_operator(input: Input<'_>) -> ParserResult<'_, SetOperator> {
)))(input)
}

fn element_set(input: Input<'_>) -> ParserResult<'_, ElementSet> {
pub fn element_set(input: Input<'_>) -> ParserResult<'_, ElementSet> {
into(pair(
alt((
map(set_operation, ElementOrSetOperation::SetOperation),
Expand Down
29 changes: 28 additions & 1 deletion rasn-compiler/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use nom::{

use crate::{
input::{context_boundary, Input},
intermediate::{information_object::*, *},
intermediate::{information_object::*, constraints::Constraint, *},
};

use self::{
Expand Down Expand Up @@ -94,6 +94,7 @@ pub(crate) fn asn_module(
ToplevelDefinition::Information,
),
map(top_level_type_declaration, ToplevelDefinition::Type),
map(top_level_valueset_declaration, ToplevelDefinition::Type),
map(top_level_value_declaration, ToplevelDefinition::Value),
)))),
context_boundary(skip_ws_and_comments(alt((end, encoding_control)))),
Expand Down Expand Up @@ -231,6 +232,32 @@ fn top_level_value_declaration(input: Input<'_>) -> ParserResult<'_, ToplevelVal
))(input)
}

fn top_level_valueset_declaration(input: Input<'_>) -> ParserResult<'_, ToplevelTypeDefinition> {
map(
tuple((
skip_ws(many0(comment)),
skip_ws(context_boundary(title_case_identifier)),
skip_ws_and_comments(opt(parameterization)),
skip_ws_and_comments(asn1_type),
preceded(assignment, in_braces(element_set))
)),
|mut value| {
if let Some(constraints) = value.3.constraints_mut() {
constraints.push(Constraint::SubtypeConstraint(value.4))
} else {
eprintln!("{name}: unable to push constraints to {ty:?}", name=value.1, ty=value.3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you return an error here instead of logging, so that we report errors consistently through the Result type?

}
ToplevelTypeDefinition{
comments: value.0.join("\n"),
tag: None,
name: value.1.to_string(),
ty: value.3,
parameterization: value.2,
index: None,
}
}
)(input)
}
fn top_level_information_object_declaration(
input: Input<'_>,
) -> ParserResult<'_, ToplevelInformationDefinition> {
Expand Down
Loading