Improve performance

This commit is contained in:
dalance 2019-08-22 21:24:57 +09:00
parent 92df1aa6db
commit c9456ee993
7 changed files with 21 additions and 20 deletions

View File

@ -11,9 +11,10 @@ trace = ["nom-tracable/trace"]
[dependencies]
nom = "5.0.0"
nom_locate = "1.0.0"
nom-packrat = "0.2.0"
#nom-packrat = "0.2.0"
nom-packrat = {path = "../../nom-packrat/nom-packrat"}
nom-recursive = {version = "0.1.1", features = ["tracer128"]}
nom-tracable = "0.3.1"
nom-tracable = "0.4.0"
str-concat = "0.1.4"
sv-parser-macros = {path = "../sv-parser-macros"}
sv-parser-syntaxtree = {path = "../sv-parser-syntaxtree"}

View File

@ -218,6 +218,9 @@ pub(crate) fn constant_indexed_range(s: Span) -> IResult<Span, ConstantIndexedRa
#[packrat_parser]
pub(crate) fn expression(s: Span) -> IResult<Span, Expression> {
alt((
map(terminated(primary, peek(one_of(",();"))), |x| {
Expression::Primary(Box::new(x))
}),
expression_binary,
map(conditional_expression, |x| {
Expression::ConditionalExpression(Box::new(x))

View File

@ -153,18 +153,18 @@ pub(crate) fn module_path_primary_mintypmax_expression(
#[packrat_parser]
pub(crate) fn primary(s: Span) -> IResult<Span, Primary> {
alt((
terminated(
primary_hierarchical,
peek(not(alt((
map(one_of("(.'"), |_| ()),
map(keyword("with"), |_| ()),
)))),
),
map(assignment_pattern_expression, |x| {
Primary::AssignmentPatternExpression(Box::new(x))
}),
map(primary_literal, |x| Primary::PrimaryLiteral(Box::new(x))),
map(cast, |x| Primary::Cast(Box::new(x))),
terminated(
primary_hierarchical,
peek(not(alt((
map(one_of("(."), |_| ()),
map(keyword("with"), |_| ()),
)))),
),
map(empty_unpacked_array_concatenation, |x| {
Primary::EmptyUnpackedArrayConcatenation(Box::new(x))
}),

View File

@ -82,7 +82,7 @@ impl HasExtraState<()> for SpanInfo {
// -----------------------------------------------------------------------------
nom_packrat::storage!(AnyNode);
nom_packrat::storage!(AnyNode, 1024);
pub fn sv_parser(s: Span) -> IResult<Span, SourceText> {
source_text(s)

View File

@ -138,10 +138,10 @@ pub(crate) fn module_item(s: Span) -> IResult<Span, ModuleItem> {
pub(crate) fn module_or_generate_item(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
alt((
module_or_generate_item_parameter,
module_or_generate_item_gate,
module_or_generate_item_udp,
module_or_generate_item_module,
module_or_generate_item_module_item,
module_or_generate_item_gate,
module_or_generate_item_udp,
))(s)
}

View File

@ -15704,10 +15704,5 @@ mod spec {
#[test]
fn debug() {
test!(
source_text,
r##"//aaa
//bbb"##,
Ok((_, _))
);
nom_tracable::cumulative_histogram();
}

View File

@ -260,8 +260,10 @@ pub(crate) fn white_space(s: Span) -> IResult<Span, WhiteSpace> {
map(multispace1, |x: Span| {
WhiteSpace::Space(Box::new(into_locate(x)))
}),
map(comment, |x| WhiteSpace::Comment(Box::new(x))),
map(compiler_directive, |x| {
map(preceded(peek(char('/')), comment), |x| {
WhiteSpace::Comment(Box::new(x))
}),
map(preceded(peek(char('`')), compiler_directive), |x| {
WhiteSpace::CompilerDirective(Box::new(x))
}),
))(s)