From 089b9e0ca77f75a725ec0f460b8b109e5aab00cd Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Tue, 8 Oct 2024 22:39:53 -0500 Subject: [PATCH] Added ability to declare enums as public --- src/ast/enumeration.rs | 3 ++- src/interpreter_env/mod.rs | 1 + src/parser/parse_enum.rs | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ast/enumeration.rs b/src/ast/enumeration.rs index 5f81c483..f384b0e0 100644 --- a/src/ast/enumeration.rs +++ b/src/ast/enumeration.rs @@ -1,4 +1,4 @@ -use super::Type; +use super::{Privacy, Type}; use crate::source_files::Source; use indexmap::IndexMap; use num::BigInt; @@ -8,6 +8,7 @@ pub struct Enum { pub backing_type: Option, pub source: Source, pub members: IndexMap, + pub privacy: Privacy, } #[derive(Clone, Debug, PartialEq)] diff --git a/src/interpreter_env/mod.rs b/src/interpreter_env/mod.rs index 56eec2e4..dfc25c12 100644 --- a/src/interpreter_env/mod.rs +++ b/src/interpreter_env/mod.rs @@ -127,6 +127,7 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) { }, ), ]), + privacy: Privacy::Private, }, ); diff --git a/src/parser/parse_enum.rs b/src/parser/parse_enum.rs index 48bb07bc..a558e459 100644 --- a/src/parser/parse_enum.rs +++ b/src/parser/parse_enum.rs @@ -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, @@ -14,14 +14,15 @@ impl<'a, I: Inflow> 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"))), } } @@ -63,6 +64,7 @@ impl<'a, I: Inflow> Parser<'a, I> { backing_type: None, members, source, + privacy, }, }) }