Skip to main content

check_syntax_partial

Function check_syntax_partial 

Source
pub fn check_syntax_partial(source: &str) -> Result<ModuleSyntax, Error>
Expand description

check_syntax for source that is one module of a larger project whose other modules are not available.

Same parse and the same rules, with one exception: a name that resolves nowhere is accepted rather than reported, since a sibling module this call cannot see may well declare it. Everything the module’s own text disproves – a syntax error, a duplicate declaration, a plain local used as a call target – is still reported.

This is strictly the weaker check, and is the scope VbaModule::check_syntax already uses. Prefer VbaProject::check_modules wherever the whole project is in hand; reach for this only when it genuinely is not, as for a .bas file cut out of a project that lives elsewhere.

use visi_core::core::{check_syntax, check_syntax_partial};
// `DoWork` is declared by some other module of the project.
let src = "Sub Caller()\n    DoWork 1\nEnd Sub\n";
assert!(check_syntax(src).is_err());
assert!(check_syntax_partial(src).is_ok());
// A fragment is still held to what its own text shows.
assert!(check_syntax_partial("Sub Caller()\n").is_err());