Fix error position
This commit is contained in:
parent
b26b56d624
commit
8bc0052dbc
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.9.0...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.9.0...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Fixed] wrong error position
|
||||||
* [Fixed] escaped_ideitifier at macro name [#28](https://github.com/dalance/sv-parser/issues/28)
|
* [Fixed] escaped_ideitifier at macro name [#28](https://github.com/dalance/sv-parser/issues/28)
|
||||||
* [Fixed] begin_keywords "1364-2001-noconfig" failure [#28](https://github.com/dalance/sv-parser/issues/28)
|
* [Fixed] begin_keywords "1364-2001-noconfig" failure [#28](https://github.com/dalance/sv-parser/issues/28)
|
||||||
* [Changed] update nom to 6.0.0
|
* [Changed] update nom to 6.0.0
|
||||||
|
@ -95,11 +95,21 @@ pub fn sv_parser(s: Span) -> IResult<Span, SourceText> {
|
|||||||
source_text(s)
|
source_text(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sv_parser_incomplete(s: Span) -> IResult<Span, SourceText> {
|
||||||
|
nom_packrat::init!();
|
||||||
|
source_text_incomplete(s)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn lib_parser(s: Span) -> IResult<Span, LibraryText> {
|
pub fn lib_parser(s: Span) -> IResult<Span, LibraryText> {
|
||||||
nom_packrat::init!();
|
nom_packrat::init!();
|
||||||
library_text(s)
|
library_text(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lib_parser_incomplete(s: Span) -> IResult<Span, LibraryText> {
|
||||||
|
nom_packrat::init!();
|
||||||
|
library_text_incomplete(s)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pp_parser(s: Span) -> IResult<Span, PreprocessorText> {
|
pub fn pp_parser(s: Span) -> IResult<Span, PreprocessorText> {
|
||||||
nom_packrat::init!();
|
nom_packrat::init!();
|
||||||
preprocessor_text(s)
|
preprocessor_text(s)
|
||||||
|
@ -5,6 +5,14 @@ use crate::*;
|
|||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn library_text(s: Span) -> IResult<Span, LibraryText> {
|
pub(crate) fn library_text(s: Span) -> IResult<Span, LibraryText> {
|
||||||
|
let (s, a) = many0(white_space)(s)?;
|
||||||
|
let (s, (b, _)) = many_till(library_description, eof)(s)?;
|
||||||
|
Ok((s, LibraryText { nodes: (a, b) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracable_parser]
|
||||||
|
#[packrat_parser]
|
||||||
|
pub(crate) fn library_text_incomplete(s: Span) -> IResult<Span, LibraryText> {
|
||||||
let (s, a) = many0(white_space)(s)?;
|
let (s, a) = many0(white_space)(s)?;
|
||||||
let (s, b) = many0(library_description)(s)?;
|
let (s, b) = many0(library_description)(s)?;
|
||||||
Ok((s, LibraryText { nodes: (a, b) }))
|
Ok((s, LibraryText { nodes: (a, b) }))
|
||||||
|
@ -5,6 +5,15 @@ use crate::*;
|
|||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn source_text(s: Span) -> IResult<Span, SourceText> {
|
pub(crate) fn source_text(s: Span) -> IResult<Span, SourceText> {
|
||||||
|
let (s, a) = many0(white_space)(s)?;
|
||||||
|
let (s, b) = opt(timeunits_declaration)(s)?;
|
||||||
|
let (s, (c, _)) = many_till(description, eof)(s)?;
|
||||||
|
Ok((s, SourceText { nodes: (a, b, c) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracable_parser]
|
||||||
|
#[packrat_parser]
|
||||||
|
pub(crate) fn source_text_incomplete(s: Span) -> IResult<Span, SourceText> {
|
||||||
let (s, a) = many0(white_space)(s)?;
|
let (s, a) = many0(white_space)(s)?;
|
||||||
let (s, b) = opt(timeunits_declaration)(s)?;
|
let (s, b) = opt(timeunits_declaration)(s)?;
|
||||||
let (s, c) = many0(description)(s)?;
|
let (s, c) = many0(description)(s)?;
|
||||||
|
@ -22,6 +22,26 @@ macro_rules! test {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! error_test {
|
||||||
|
( $x:expr, $y:expr, $p:expr ) => {
|
||||||
|
nom_packrat::init!();
|
||||||
|
let info = SpanInfo::default();
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let info = info.set_tracable_info(
|
||||||
|
info.get_tracable_info()
|
||||||
|
//.fold("white_space")
|
||||||
|
.fold("number")
|
||||||
|
.fold("binary_operator")
|
||||||
|
.fold("unary_operator"),
|
||||||
|
);
|
||||||
|
let ret = all_consuming($x)(Span::new_extra($y, info));
|
||||||
|
match ret {
|
||||||
|
Err(Err::Error(e)) => assert_eq!(nom_greedyerror::error_position(&e), $p),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
mod unit {
|
mod unit {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -15893,6 +15913,19 @@ mod spec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod error {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test1() {
|
||||||
|
error_test!(
|
||||||
|
source_text,
|
||||||
|
r##"module A(); parameter A = 1 endmodule"##,
|
||||||
|
Some(12)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debug() {
|
fn debug() {
|
||||||
test!(
|
test!(
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
use nom::combinator::all_consuming;
|
|
||||||
use nom_greedyerror::error_position;
|
use nom_greedyerror::error_position;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::BuildHasher;
|
use std::hash::BuildHasher;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
pub use sv_parser_error::Error;
|
pub use sv_parser_error::Error;
|
||||||
use sv_parser_parser::{lib_parser, sv_parser, Span, SpanInfo};
|
use sv_parser_parser::{
|
||||||
|
lib_parser, lib_parser_incomplete, sv_parser, sv_parser_incomplete, Span, SpanInfo,
|
||||||
|
};
|
||||||
pub use sv_parser_pp::preprocess::{
|
pub use sv_parser_pp::preprocess::{
|
||||||
preprocess, preprocess_str, Define, DefineText, Defines, PreprocessedText,
|
preprocess, preprocess_str, Define, DefineText, Defines, PreprocessedText,
|
||||||
};
|
};
|
||||||
@ -110,9 +111,9 @@ pub fn parse_sv_pp(
|
|||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let span = Span::new_extra(text.text(), SpanInfo::default());
|
let span = Span::new_extra(text.text(), SpanInfo::default());
|
||||||
let result = if allow_incomplete {
|
let result = if allow_incomplete {
|
||||||
sv_parser(span)
|
sv_parser_incomplete(span)
|
||||||
} else {
|
} else {
|
||||||
all_consuming(sv_parser)(span)
|
sv_parser(span)
|
||||||
};
|
};
|
||||||
match result {
|
match result {
|
||||||
Ok((_, x)) => Ok((
|
Ok((_, x)) => Ok((
|
||||||
@ -200,7 +201,7 @@ pub fn parse_lib_pp(
|
|||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let span = Span::new_extra(text.text(), SpanInfo::default());
|
let span = Span::new_extra(text.text(), SpanInfo::default());
|
||||||
let result = if allow_incomplete {
|
let result = if allow_incomplete {
|
||||||
all_consuming(lib_parser)(span)
|
lib_parser_incomplete(span)
|
||||||
} else {
|
} else {
|
||||||
lib_parser(span)
|
lib_parser(span)
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user