Add incomplete option #19
This commit is contained in:
parent
ce598fd4ef
commit
e80104111a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.8.3...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.8.3...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Added] incomplete option [#19](https://github.com/dalance/sv-parser/issues/19)
|
||||||
* [Changed] keep text_macro_definition after preprocess [#19](https://github.com/dalance/sv-parser/issues/19)
|
* [Changed] keep text_macro_definition after preprocess [#19](https://github.com/dalance/sv-parser/issues/19)
|
||||||
|
|
||||||
## [v0.8.3](https://github.com/dalance/sv-parser/compare/v0.8.2...v0.8.3) - 2020-11-06
|
## [v0.8.3](https://github.com/dalance/sv-parser/compare/v0.8.2...v0.8.3) - 2020-11-06
|
||||||
|
@ -7,8 +7,8 @@ use crate::*;
|
|||||||
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, a) = many0(white_space)(s)?;
|
||||||
let (s, b) = opt(timeunits_declaration)(s)?;
|
let (s, b) = opt(timeunits_declaration)(s)?;
|
||||||
let (s, c) = many_till(description, eof)(s)?;
|
let (s, c) = many0(description)(s)?;
|
||||||
Ok((s, SourceText { nodes: (a, b, c.0) }))
|
Ok((s, SourceText { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
|
@ -301,16 +301,6 @@ where
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub(crate) fn eof(s: Span) -> IResult<Span, Span> {
|
|
||||||
use nom::InputLength;
|
|
||||||
|
|
||||||
if s.input_len() == 0 {
|
|
||||||
Ok((s, s))
|
|
||||||
} else {
|
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Eof)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn white_space(s: Span) -> IResult<Span, WhiteSpace> {
|
pub(crate) fn white_space(s: Span) -> IResult<Span, WhiteSpace> {
|
||||||
|
@ -14,7 +14,7 @@ fn main() {
|
|||||||
let includes: Vec<PathBuf> = Vec::new();
|
let includes: Vec<PathBuf> = Vec::new();
|
||||||
|
|
||||||
// Parse
|
// Parse
|
||||||
let result = parse_sv(&path, &defines, &includes, false);
|
let result = parse_sv(&path, &defines, &includes, false, false);
|
||||||
|
|
||||||
if let Ok((syntax_tree, _)) = result {
|
if let Ok((syntax_tree, _)) = result {
|
||||||
// &SyntexTree is iterable
|
// &SyntexTree is iterable
|
||||||
|
@ -25,6 +25,10 @@ struct Opt {
|
|||||||
#[structopt(short = "p", long = "pp")]
|
#[structopt(short = "p", long = "pp")]
|
||||||
pub pp: bool,
|
pub pp: bool,
|
||||||
|
|
||||||
|
/// Allow incomplete source code
|
||||||
|
#[structopt(long = "incomplete")]
|
||||||
|
pub incomplete: bool,
|
||||||
|
|
||||||
/// Quiet
|
/// Quiet
|
||||||
#[structopt(short = "q", long = "quiet")]
|
#[structopt(short = "q", long = "quiet")]
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
@ -44,7 +48,7 @@ fn main() {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match parse_sv(&path, &defines, &opt.includes, false) {
|
match parse_sv(&path, &defines, &opt.includes, false, opt.incomplete) {
|
||||||
Ok((syntax_tree, new_defines)) => {
|
Ok((syntax_tree, new_defines)) => {
|
||||||
if opt.tree {
|
if opt.tree {
|
||||||
println!("{}", syntax_tree);
|
println!("{}", syntax_tree);
|
||||||
|
@ -97,17 +97,23 @@ pub fn parse_sv<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
pre_defines: &HashMap<String, Option<Define>, V>,
|
pre_defines: &HashMap<String, Option<Define>, V>,
|
||||||
include_paths: &[U],
|
include_paths: &[U],
|
||||||
ignore_include: bool,
|
ignore_include: bool,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let (text, defines) = preprocess(path, pre_defines, include_paths, false, ignore_include)?;
|
let (text, defines) = preprocess(path, pre_defines, include_paths, false, ignore_include)?;
|
||||||
parse_sv_pp(text, defines)
|
parse_sv_pp(text, defines, allow_incomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_sv_pp(
|
pub fn parse_sv_pp(
|
||||||
text: PreprocessedText,
|
text: PreprocessedText,
|
||||||
defines: Defines,
|
defines: Defines,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> 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 = all_consuming(sv_parser)(span);
|
let result = if allow_incomplete {
|
||||||
|
sv_parser(span)
|
||||||
|
} else {
|
||||||
|
all_consuming(sv_parser)(span)
|
||||||
|
};
|
||||||
match result {
|
match result {
|
||||||
Ok((_, x)) => Ok((
|
Ok((_, x)) => Ok((
|
||||||
SyntaxTree {
|
SyntaxTree {
|
||||||
@ -142,6 +148,7 @@ pub fn parse_sv_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
pre_defines: &HashMap<String, Option<Define>, V>,
|
pre_defines: &HashMap<String, Option<Define>, V>,
|
||||||
include_paths: &[U],
|
include_paths: &[U],
|
||||||
ignore_include: bool,
|
ignore_include: bool,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let (text, defines) = preprocess_str(
|
let (text, defines) = preprocess_str(
|
||||||
s,
|
s,
|
||||||
@ -152,7 +159,7 @@ pub fn parse_sv_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
)?;
|
)?;
|
||||||
parse_sv_pp(text, defines)
|
parse_sv_pp(text, defines, allow_incomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
||||||
@ -160,9 +167,10 @@ pub fn parse_lib<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
pre_defines: &HashMap<String, Option<Define>, V>,
|
pre_defines: &HashMap<String, Option<Define>, V>,
|
||||||
include_paths: &[U],
|
include_paths: &[U],
|
||||||
ignore_include: bool,
|
ignore_include: bool,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let (text, defines) = preprocess(path, pre_defines, include_paths, false, ignore_include)?;
|
let (text, defines) = preprocess(path, pre_defines, include_paths, false, ignore_include)?;
|
||||||
parse_lib_pp(text, defines)
|
parse_lib_pp(text, defines, allow_incomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
||||||
@ -171,6 +179,7 @@ pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
pre_defines: &HashMap<String, Option<Define>, V>,
|
pre_defines: &HashMap<String, Option<Define>, V>,
|
||||||
include_paths: &[U],
|
include_paths: &[U],
|
||||||
ignore_include: bool,
|
ignore_include: bool,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> Result<(SyntaxTree, Defines), Error> {
|
) -> Result<(SyntaxTree, Defines), Error> {
|
||||||
let (text, defines) = preprocess_str(
|
let (text, defines) = preprocess_str(
|
||||||
s,
|
s,
|
||||||
@ -181,15 +190,20 @@ pub fn parse_lib_str<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
|||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
)?;
|
)?;
|
||||||
parse_lib_pp(text, defines)
|
parse_lib_pp(text, defines, allow_incomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_lib_pp(
|
pub fn parse_lib_pp(
|
||||||
text: PreprocessedText,
|
text: PreprocessedText,
|
||||||
defines: Defines,
|
defines: Defines,
|
||||||
|
allow_incomplete: bool,
|
||||||
) -> 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 = all_consuming(lib_parser)(span);
|
let result = if allow_incomplete {
|
||||||
|
all_consuming(lib_parser)(span)
|
||||||
|
} else {
|
||||||
|
lib_parser(span)
|
||||||
|
};
|
||||||
match result {
|
match result {
|
||||||
Ok((_, x)) => Ok((
|
Ok((_, x)) => Ok((
|
||||||
SyntaxTree {
|
SyntaxTree {
|
||||||
@ -258,7 +272,7 @@ mod test {
|
|||||||
fn test() {
|
fn test() {
|
||||||
let src = "/* comment */";
|
let src = "/* comment */";
|
||||||
let (syntax_tree, _) =
|
let (syntax_tree, _) =
|
||||||
parse_sv_str(src, PathBuf::from(""), &HashMap::new(), &[""], false).unwrap();
|
parse_sv_str(src, PathBuf::from(""), &HashMap::new(), &[""], false, false).unwrap();
|
||||||
let comment = unwrap_node!(&syntax_tree, Comment);
|
let comment = unwrap_node!(&syntax_tree, Comment);
|
||||||
assert!(comment.is_some());
|
assert!(comment.is_some());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user