2022-02-02 23:54:50 +00:00
|
|
|
pub mod adt;
|
|
|
|
pub mod comb;
|
2022-02-02 00:41:19 +00:00
|
|
|
pub mod declaration;
|
2022-02-01 18:46:06 +00:00
|
|
|
pub mod error;
|
2022-02-02 00:31:59 +00:00
|
|
|
pub mod expression;
|
2022-02-01 18:46:06 +00:00
|
|
|
mod literals;
|
2022-01-17 00:15:27 +00:00
|
|
|
pub mod module;
|
|
|
|
pub mod proc;
|
2022-02-01 22:14:11 +00:00
|
|
|
pub mod tokens;
|
2022-01-16 21:06:52 +00:00
|
|
|
|
2022-01-14 14:32:00 +00:00
|
|
|
use nom_locate::LocatedSpan;
|
2022-01-04 16:28:43 +00:00
|
|
|
|
|
|
|
// custom span type for nom_locate
|
2022-01-04 19:05:10 +00:00
|
|
|
pub type Span<'a> = LocatedSpan<&'a str>;
|
2022-01-04 16:24:49 +00:00
|
|
|
|
2022-02-02 23:05:10 +00:00
|
|
|
pub type IErr<I> = error::Error<I>;
|
2022-01-04 16:28:43 +00:00
|
|
|
// custom IResult type for VerboseError
|
2022-02-01 01:00:27 +00:00
|
|
|
pub type IResult<I, O, E = IErr<I>> = nom::IResult<I, O, E>;
|
2022-01-04 16:28:43 +00:00
|
|
|
|
2022-02-02 00:41:19 +00:00
|
|
|
pub use crate::parser::declaration::{
|
|
|
|
assign_statement, declaration, typename, Assign, NetDecl, TypeName,
|
|
|
|
};
|
2022-02-02 00:31:59 +00:00
|
|
|
pub use crate::parser::expression::{expression, Call, Expression, Operation};
|
2022-01-16 21:06:52 +00:00
|
|
|
pub use crate::parser::module::{module, Module, ModuleItem, PortDirection};
|
2022-02-02 23:08:45 +00:00
|
|
|
use crate::parser::tokens::TokenSpan;
|
2022-01-01 21:43:38 +00:00
|
|
|
|
2022-02-02 00:00:11 +00:00
|
|
|
pub fn parse(input: TokenSpan) -> IResult<TokenSpan, Module> {
|
|
|
|
module(input)
|
2022-01-04 16:24:21 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 21:43:38 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2022-01-17 00:15:27 +00:00
|
|
|
use nom::combinator::all_consuming;
|
2022-01-01 21:43:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_operation() {
|
2022-01-04 19:05:10 +00:00
|
|
|
operation(" a | b ".into()).unwrap();
|
|
|
|
operation(" a & b ".into()).unwrap();
|
2022-01-01 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_expression() {
|
2022-01-04 19:05:10 +00:00
|
|
|
expression(" a ".into()).unwrap();
|
|
|
|
expression(" a | b ".into()).unwrap();
|
|
|
|
expression(" a | b | c ".into()).unwrap();
|
2022-01-01 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_assignment() {
|
2022-01-17 00:15:27 +00:00
|
|
|
// TODO: make wrapper and use for all tests
|
|
|
|
all_consuming(assign_statement)(" a = b ".into()).unwrap();
|
|
|
|
all_consuming(assign_statement)(" a = b | c ".into()).unwrap();
|
2022-01-01 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_call() {
|
2022-01-04 19:05:10 +00:00
|
|
|
call_item("thing ( )".into()).unwrap();
|
|
|
|
call_item("thing ( a , b , c )".into()).unwrap();
|
|
|
|
call_item("thing(a,b,c)".into()).unwrap();
|
2022-01-01 21:43:38 +00:00
|
|
|
}
|
|
|
|
}
|