Add empty define support
This commit is contained in:
parent
a733e3b980
commit
07461243a5
@ -3,6 +3,7 @@
|
|||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.3.4...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.3.4...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
* [Added] LF/CR+LF support
|
* [Added] LF/CR+LF support
|
||||||
|
* [Added] empty define support
|
||||||
|
|
||||||
## [v0.3.4](https://github.com/dalance/sv-parser/compare/v0.3.3...v0.3.4) - 2019-11-05
|
## [v0.3.4](https://github.com/dalance/sv-parser/compare/v0.3.3...v0.3.4) - 2019-11-05
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ pub enum ErrorKind {
|
|||||||
Preprocess,
|
Preprocess,
|
||||||
#[fail(display = "Define argument not found: {}", _0)]
|
#[fail(display = "Define argument not found: {}", _0)]
|
||||||
DefineArgNotFound(String),
|
DefineArgNotFound(String),
|
||||||
#[fail(display = "Define text not found: {}", _0)]
|
|
||||||
DefineTextNotFound(String),
|
|
||||||
#[fail(display = "Define not found: {}", _0)]
|
#[fail(display = "Define not found: {}", _0)]
|
||||||
DefineNotFound(String),
|
DefineNotFound(String),
|
||||||
}
|
}
|
||||||
|
@ -296,10 +296,14 @@ fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
IncludeCompilerDirective::TextMacroUsage(x) => {
|
IncludeCompilerDirective::TextMacroUsage(x) => {
|
||||||
let (_, _, ref x) = x.nodes;
|
let (_, _, ref x) = x.nodes;
|
||||||
skip_nodes.push(x.into());
|
skip_nodes.push(x.into());
|
||||||
let (p, _, _, _) =
|
if let Some((p, _, _, _)) =
|
||||||
resolve_text_macro_usage(x, s, path.as_ref(), &defines, include_paths)?;
|
resolve_text_macro_usage(x, s, path.as_ref(), &defines, include_paths)?
|
||||||
|
{
|
||||||
let p = p.trim().trim_matches('"');
|
let p = p.trim().trim_matches('"');
|
||||||
PathBuf::from(p)
|
PathBuf::from(p)
|
||||||
|
} else {
|
||||||
|
PathBuf::from("")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
@ -319,11 +323,13 @@ fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
ret.merge(include);
|
ret.merge(include);
|
||||||
}
|
}
|
||||||
NodeEvent::Enter(RefNode::TextMacroUsage(x)) if !skip => {
|
NodeEvent::Enter(RefNode::TextMacroUsage(x)) if !skip => {
|
||||||
let (text, path, range, new_defines) =
|
if let Some((text, path, range, new_defines)) =
|
||||||
resolve_text_macro_usage(x, s, path.as_ref(), &defines, include_paths)?;
|
resolve_text_macro_usage(x, s, path.as_ref(), &defines, include_paths)?
|
||||||
|
{
|
||||||
ret.push(&text, path, range);
|
ret.push(&text, path, range);
|
||||||
defines = new_defines;
|
defines = new_defines;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,7 +401,7 @@ fn resolve_text_macro_usage<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
path: T,
|
path: T,
|
||||||
defines: &Defines,
|
defines: &Defines,
|
||||||
include_paths: &[U],
|
include_paths: &[U],
|
||||||
) -> Result<(String, PathBuf, Range, Defines), Error> {
|
) -> Result<Option<(String, PathBuf, Range, Defines)>, Error> {
|
||||||
let (_, ref name, ref args) = x.nodes;
|
let (_, ref name, ref args) = x.nodes;
|
||||||
let id = identifier((&name.nodes.0).into(), &s).unwrap();
|
let id = identifier((&name.nodes.0).into(), &s).unwrap();
|
||||||
|
|
||||||
@ -448,17 +454,17 @@ fn resolve_text_macro_usage<T: AsRef<Path>, U: AsRef<Path>>(
|
|||||||
|
|
||||||
let (replaced, new_defines) =
|
let (replaced, new_defines) =
|
||||||
preprocess_str(&replaced, path.as_ref(), &defines, include_paths)?;
|
preprocess_str(&replaced, path.as_ref(), &defines, include_paths)?;
|
||||||
Ok((
|
Ok(Some((
|
||||||
String::from(replaced.text()),
|
String::from(replaced.text()),
|
||||||
define.path.clone(),
|
define.path.clone(),
|
||||||
*range,
|
*range,
|
||||||
new_defines,
|
new_defines,
|
||||||
))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Err(ErrorKind::DefineTextNotFound(String::from(id)).into())
|
Ok(None)
|
||||||
}
|
}
|
||||||
} else if let Some(_) = define {
|
} else if let Some(_) = define {
|
||||||
Err(ErrorKind::DefineTextNotFound(String::from(id)).into())
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Err(ErrorKind::DefineNotFound(String::from(id)).into())
|
Err(ErrorKind::DefineNotFound(String::from(id)).into())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user