Skip to content

Commit

Permalink
Added ability to declare enums as public
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Oct 9, 2024
1 parent c5904b9 commit 089b9e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ast/enumeration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Type;
use super::{Privacy, Type};
use crate::source_files::Source;
use indexmap::IndexMap;
use num::BigInt;
Expand All @@ -8,6 +8,7 @@ pub struct Enum {
pub backing_type: Option<Type>,
pub source: Source,
pub members: IndexMap<String, EnumMember>,
pub privacy: Privacy,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions src/interpreter_env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
},
),
]),
privacy: Privacy::Private,
},
);

Expand Down
6 changes: 4 additions & 2 deletions src/parser/parse_enum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{annotation::Annotation, error::ParseError, Parser};
use crate::{
ast::{Enum, EnumMember, Named},
ast::{Enum, EnumMember, Named, Privacy},
inflow::Inflow,
name::Name,
parser::annotation::AnnotationKind,
Expand All @@ -14,14 +14,15 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
let source = self.source_here();
assert!(self.input.advance().is_enum_keyword());

let mut privacy = Privacy::Private;
let mut namespace = None;
let name = self.parse_identifier(Some("for enum name after 'enum' keyword"))?;
self.ignore_newlines();

#[allow(clippy::never_loop, clippy::match_single_binding)]
for annotation in annotations {
match annotation.kind {
AnnotationKind::Namespace(new_namespace) => namespace = Some(new_namespace),
AnnotationKind::Public => privacy = Privacy::Public,
_ => return Err(self.unexpected_annotation(&annotation, Some("for enum"))),
}
}
Expand Down Expand Up @@ -63,6 +64,7 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
backing_type: None,
members,
source,
privacy,
},
})
}
Expand Down

0 comments on commit 089b9e0

Please sign in to comment.