use nom::IResult;
pub(crate) use expression::parse_expression;
pub(crate) use instruction::parse_instructions;
pub(crate) use lexer::lex;
mod command;
mod gate;
mod macros;
pub(crate) mod common;
mod error;
mod expression;
pub(crate) mod instruction;
mod lexer;
pub(crate) mod pragma_extern;
mod token;
pub(crate) use error::{ErrorInput, InternalParseError};
pub use error::{ParseError, ParserErrorKind};
pub use lexer::{Command, DataType, LexError, Modifier};
pub use token::{KeywordToken, Token, TokenWithLocation};
pub(crate) type ParserInput<'a> = &'a [TokenWithLocation<'a>];
type InternalParserResult<'a, R, E = InternalParseError<'a>> = IResult<ParserInput<'a>, R, E>;
pub(crate) fn split_first_token(input: ParserInput<'_>) -> Option<(&Token, ParserInput<'_>)> {
input
.split_first()
.map(|(first, rest)| (first.as_token(), rest))
}
pub(crate) fn first_token(input: ParserInput<'_>) -> Option<&Token> {
input.first().map(TokenWithLocation::as_token)
}
pub(crate) fn extract_nom_err<E>(err: nom::Err<E>) -> E {
match err {
nom::Err::Incomplete(_) => {
unreachable!("can't be incomplete if all parsers are complete variants")
}
nom::Err::Error(inner) => inner,
nom::Err::Failure(inner) => inner,
}
}