Refactoring
This commit is contained in:
parent
dfbd0718f9
commit
5211f96d95
@ -29,9 +29,9 @@ A parser library for System Verilog.
|
|||||||
| declaration | task_declarations | x | x | |
|
| declaration | task_declarations | x | x | |
|
||||||
| declaration | block_item_declarations | x | x | |
|
| declaration | block_item_declarations | x | x | |
|
||||||
| declaration | interface_declarations | x | x | |
|
| declaration | interface_declarations | x | x | |
|
||||||
| declaration | assertion_declarations | x | | |
|
| declaration | assertion_declarations | x | x | |
|
||||||
| declaration | covergroup_declarations | | | |
|
| declaration | covergroup_declarations | x | x | |
|
||||||
| declaration | let_declarations | | | |
|
| declaration | let_declarations | x | x | |
|
||||||
| primitive_instance | primitive_instantiation_and_instances | x | x | |
|
| primitive_instance | primitive_instantiation_and_instances | x | x | |
|
||||||
| primitive_instance | primitive_strengths | x | x | x |
|
| primitive_instance | primitive_strengths | x | x | x |
|
||||||
| primitive_instance | primitive_terminals | x | x | |
|
| primitive_instance | primitive_terminals | x | x | |
|
||||||
@ -44,7 +44,7 @@ A parser library for System Verilog.
|
|||||||
| udp_declaration_and_instantiation | udp_declaration | | | |
|
| udp_declaration_and_instantiation | udp_declaration | | | |
|
||||||
| udp_declaration_and_instantiation | udp_ports | | | |
|
| udp_declaration_and_instantiation | udp_ports | | | |
|
||||||
| udp_declaration_and_instantiation | udp_body | | | |
|
| udp_declaration_and_instantiation | udp_body | | | |
|
||||||
| udp_declaration_and_instantiation | udp_instantiation | | | |
|
| udp_declaration_and_instantiation | udp_instantiation | x | x | |
|
||||||
| behavioral_statements | continuous_assignment_and_net_alias | x | x | |
|
| behavioral_statements | continuous_assignment_and_net_alias | x | x | |
|
||||||
| behavioral_statements | procedural_blocks_and_assignments | x | x | |
|
| behavioral_statements | procedural_blocks_and_assignments | x | x | |
|
||||||
| behavioral_statements | parallel_and_sequential_blocks | x | x | |
|
| behavioral_statements | parallel_and_sequential_blocks | x | x | |
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,23 @@
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
//use nom::branch::*;
|
use nom::branch::*;
|
||||||
//use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
use nom::error::*;
|
use nom::multi::*;
|
||||||
use nom::{Err, IResult};
|
use nom::sequence::*;
|
||||||
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct LetDeclaration<'a> {
|
pub struct LetDeclaration<'a> {
|
||||||
pub nodes: (LetIdentifier<'a>, Option<LetPortList<'a>>, Expression<'a>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
LetIdentifier<'a>,
|
||||||
|
Option<Paren<'a, Option<LetPortList<'a>>>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Expression<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -19,7 +27,7 @@ pub struct LetIdentifier<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct LetPortList<'a> {
|
pub struct LetPortList<'a> {
|
||||||
pub nodes: (Vec<LetPortItem<'a>>,),
|
pub nodes: (List<Symbol<'a>, LetPortItem<'a>>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -27,9 +35,9 @@ pub struct LetPortItem<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
LetFormalType<'a>,
|
LetFormalType<'a>,
|
||||||
Identifier<'a>,
|
FormalPortIdentifier<'a>,
|
||||||
Vec<VariableDimension<'a>>,
|
Vec<VariableDimension<'a>>,
|
||||||
Option<Expression<'a>>,
|
Option<(Symbol<'a>, Expression<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +52,7 @@ pub struct LetExpression<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
Option<PackageScope<'a>>,
|
Option<PackageScope<'a>>,
|
||||||
LetIdentifier<'a>,
|
LetIdentifier<'a>,
|
||||||
Option<LetListOfArguments<'a>>,
|
Option<Paren<'a, Option<LetListOfArguments<'a>>>>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,14 +65,28 @@ pub enum LetListOfArguments<'a> {
|
|||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct LetListOfArgumentsOrdered<'a> {
|
pub struct LetListOfArgumentsOrdered<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
Vec<LetActualArg<'a>>,
|
List<Symbol<'a>, Option<LetActualArg<'a>>>,
|
||||||
Vec<(Identifier<'a>, LetActualArg<'a>)>,
|
Vec<(
|
||||||
|
Symbol<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Identifier<'a>,
|
||||||
|
Paren<'a, Option<LetActualArg<'a>>>,
|
||||||
|
)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct LetListOfArgumentsNamed<'a> {
|
pub struct LetListOfArgumentsNamed<'a> {
|
||||||
pub nodes: (Vec<(Identifier<'a>, LetActualArg<'a>)>,),
|
pub nodes: (
|
||||||
|
List<
|
||||||
|
Symbol<'a>,
|
||||||
|
(
|
||||||
|
Symbol<'a>,
|
||||||
|
Identifier<'a>,
|
||||||
|
Paren<'a, Option<LetActualArg<'a>>>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -75,33 +97,90 @@ pub struct LetActualArg<'a> {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn let_declaration(s: Span) -> IResult<Span, LetDeclaration> {
|
pub fn let_declaration(s: Span) -> IResult<Span, LetDeclaration> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = symbol("let")(s)?;
|
||||||
|
let (s, b) = let_identifier(s)?;
|
||||||
|
let (s, c) = opt(paren(opt(let_port_list)))(s)?;
|
||||||
|
let (s, d) = symbol("=")(s)?;
|
||||||
|
let (s, e) = expression(s)?;
|
||||||
|
let (s, f) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
LetDeclaration {
|
||||||
|
nodes: (a, b, c, d, e, f),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_identifier(s: Span) -> IResult<Span, LetIdentifier> {
|
pub fn let_identifier(s: Span) -> IResult<Span, LetIdentifier> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = identifier(s)?;
|
||||||
|
Ok((s, LetIdentifier { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_port_list(s: Span) -> IResult<Span, LetPortList> {
|
pub fn let_port_list(s: Span) -> IResult<Span, LetPortList> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = list(symbol(","), let_port_item)(s)?;
|
||||||
|
Ok((s, LetPortList { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_port_item(s: Span) -> IResult<Span, LetPortItem> {
|
pub fn let_port_item(s: Span) -> IResult<Span, LetPortItem> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = let_formal_type(s)?;
|
||||||
|
let (s, c) = formal_port_identifier(s)?;
|
||||||
|
let (s, d) = many0(variable_dimension)(s)?;
|
||||||
|
let (s, e) = opt(pair(symbol("="), expression))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
LetPortItem {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_formal_type(s: Span) -> IResult<Span, LetFormalType> {
|
pub fn let_formal_type(s: Span) -> IResult<Span, LetFormalType> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(data_type_or_implicit, |x| {
|
||||||
|
LetFormalType::DataTypeOrImplicit(x)
|
||||||
|
}),
|
||||||
|
map(symbol("untyped"), |x| LetFormalType::Untyped(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_expression(s: Span) -> IResult<Span, LetExpression> {
|
pub fn let_expression(s: Span) -> IResult<Span, LetExpression> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = opt(package_scope)(s)?;
|
||||||
|
let (s, b) = let_identifier(s)?;
|
||||||
|
let (s, c) = opt(paren(opt(let_list_of_arguments)))(s)?;
|
||||||
|
Ok((s, LetExpression { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_list_of_arguments(s: Span) -> IResult<Span, LetListOfArguments> {
|
pub fn let_list_of_arguments(s: Span) -> IResult<Span, LetListOfArguments> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((let_list_of_arguments_ordered, let_list_of_arguments_named))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn let_list_of_arguments_ordered(s: Span) -> IResult<Span, LetListOfArguments> {
|
||||||
|
let (s, a) = list(symbol(","), opt(let_actual_arg))(s)?;
|
||||||
|
let (s, b) = many0(tuple((
|
||||||
|
symbol(","),
|
||||||
|
symbol("."),
|
||||||
|
identifier,
|
||||||
|
paren(opt(let_actual_arg)),
|
||||||
|
)))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
LetListOfArguments::Ordered(LetListOfArgumentsOrdered { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn let_list_of_arguments_named(s: Span) -> IResult<Span, LetListOfArguments> {
|
||||||
|
let (s, a) = list(
|
||||||
|
symbol(","),
|
||||||
|
triple(symbol("."), identifier, paren(opt(let_actual_arg))),
|
||||||
|
)(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
LetListOfArguments::Named(LetListOfArgumentsNamed { nodes: (a,) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn let_actual_arg(s: Span) -> IResult<Span, LetActualArg> {
|
pub fn let_actual_arg(s: Span) -> IResult<Span, LetActualArg> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = expression(s)?;
|
||||||
|
Ok((s, LetActualArg { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,62 @@
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
//use nom::branch::*;
|
use nom::combinator::*;
|
||||||
//use nom::combinator::*;
|
use nom::multi::*;
|
||||||
use nom::error::*;
|
use nom::sequence::*;
|
||||||
use nom::{Err, IResult};
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct UdpInstantiation<'a> {
|
pub struct UdpInstantiation<'a> {
|
||||||
pub nodes: (Identifier<'a>,),
|
pub nodes: (
|
||||||
|
UdpIdentifier<'a>,
|
||||||
|
Option<DriveStrength<'a>>,
|
||||||
|
Option<Delay2<'a>>,
|
||||||
|
List<Symbol<'a>, UdpInstance<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Node)]
|
||||||
|
pub struct UdpInstance<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
Option<NameOfInstance<'a>>,
|
||||||
|
Paren<
|
||||||
|
'a,
|
||||||
|
(
|
||||||
|
OutputTerminal<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
InputTerminal<'a>,
|
||||||
|
Vec<(Symbol<'a>, InputTerminal<'a>)>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn udp_instantiation(s: Span) -> IResult<Span, UdpInstantiation> {
|
pub fn udp_instantiation(s: Span) -> IResult<Span, UdpInstantiation> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = udp_identifier(s)?;
|
||||||
|
let (s, b) = opt(drive_strength)(s)?;
|
||||||
|
let (s, c) = opt(delay2)(s)?;
|
||||||
|
let (s, d) = list(symbol(","), udp_instance)(s)?;
|
||||||
|
let (s, e) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
UdpInstantiation {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn udp_instance(s: Span) -> IResult<Span, UdpInstance> {
|
||||||
|
let (s, a) = opt(name_of_instance)(s)?;
|
||||||
|
let (s, b) = paren(tuple((
|
||||||
|
output_terminal,
|
||||||
|
symbol(","),
|
||||||
|
input_terminal,
|
||||||
|
many0(pair(symbol(","), input_terminal)),
|
||||||
|
)))(s)?;
|
||||||
|
Ok((s, UdpInstance { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user