use crate::{InputValue, MainInput, Registers};
use leo_input::{
sections::{Header, Section},
InputParserError,
};
#[derive(Clone, PartialEq, Eq, Default)]
pub struct ProgramInput {
pub main: MainInput,
registers: Registers,
}
#[allow(clippy::len_without_is_empty)]
impl ProgramInput {
pub fn new() -> Self {
Self::default()
}
pub fn empty(&self) -> Self {
let main = self.main.empty();
let registers = self.registers.empty();
Self { main, registers }
}
pub fn len(&self) -> usize {
let mut len = 0;
len += self.main.len();
if self.registers.is_present() {
len += 1;
}
len
}
pub fn parse(&mut self, section: Section) -> Result<(), InputParserError> {
match section.header {
Header::Main(_main) => self.main.parse(section.definitions),
Header::Registers(_registers) => self.registers.parse(section.definitions),
header => Err(InputParserError::input_section_header(header)),
}
}
#[allow(clippy::ptr_arg)]
pub fn get(&self, name: &String) -> Option<Option<InputValue>> {
self.main.get(name)
}
pub fn get_registers(&self) -> &Registers {
&self.registers
}
}