mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Fix how we pass error list output parameter when parsing AST
This makes it more convenient to pass None.
This commit is contained in:
parent
22c8e9f60d
commit
966dc0d997
2 changed files with 30 additions and 42 deletions
|
@ -2274,7 +2274,7 @@ impl Ast {
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
src: &wstr,
|
src: &wstr,
|
||||||
flags: ParseTreeFlags,
|
flags: ParseTreeFlags,
|
||||||
out_errors: &mut Option<ParseErrorList>,
|
out_errors: Option<&mut ParseErrorList>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
parse_from_top(src, flags, out_errors, Type::job_list)
|
parse_from_top(src, flags, out_errors, Type::job_list)
|
||||||
}
|
}
|
||||||
|
@ -2282,7 +2282,7 @@ impl Ast {
|
||||||
pub fn parse_argument_list(
|
pub fn parse_argument_list(
|
||||||
src: &wstr,
|
src: &wstr,
|
||||||
flags: ParseTreeFlags,
|
flags: ParseTreeFlags,
|
||||||
out_errors: &mut Option<ParseErrorList>,
|
out_errors: Option<&mut ParseErrorList>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
parse_from_top(src, flags, out_errors, Type::freestanding_argument_list)
|
parse_from_top(src, flags, out_errors, Type::freestanding_argument_list)
|
||||||
}
|
}
|
||||||
|
@ -2626,7 +2626,7 @@ struct Populator<'a> {
|
||||||
depth: usize,
|
depth: usize,
|
||||||
|
|
||||||
// If non-null, populate with errors.
|
// If non-null, populate with errors.
|
||||||
out_errors: &'a mut Option<ParseErrorList>,
|
out_errors: Option<&'a mut ParseErrorList>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> NodeVisitorMut for Populator<'s> {
|
impl<'s> NodeVisitorMut for Populator<'s> {
|
||||||
|
@ -2885,7 +2885,7 @@ impl<'s> Populator<'s> {
|
||||||
src: &'s wstr,
|
src: &'s wstr,
|
||||||
flags: ParseTreeFlags,
|
flags: ParseTreeFlags,
|
||||||
top_type: Type,
|
top_type: Type,
|
||||||
out_errors: &'s mut Option<ParseErrorList>,
|
out_errors: Option<&'s mut ParseErrorList>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
flags,
|
flags,
|
||||||
|
@ -3758,7 +3758,7 @@ enum ParserStatus {
|
||||||
fn parse_from_top(
|
fn parse_from_top(
|
||||||
src: &wstr,
|
src: &wstr,
|
||||||
flags: ParseTreeFlags,
|
flags: ParseTreeFlags,
|
||||||
out_errors: &mut Option<ParseErrorList>,
|
out_errors: Option<&mut ParseErrorList>,
|
||||||
top_type: Type,
|
top_type: Type,
|
||||||
) -> Ast {
|
) -> Ast {
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -3895,7 +3895,7 @@ use crate::ffi_tests::add_test;
|
||||||
add_test!("test_ast_parse", || {
|
add_test!("test_ast_parse", || {
|
||||||
use crate::parse_constants::PARSE_FLAG_NONE;
|
use crate::parse_constants::PARSE_FLAG_NONE;
|
||||||
let src = L!("echo");
|
let src = L!("echo");
|
||||||
let ast = Ast::parse(src, PARSE_FLAG_NONE, &mut None);
|
let ast = Ast::parse(src, PARSE_FLAG_NONE, None);
|
||||||
assert!(!ast.any_error);
|
assert!(!ast.any_error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4391,20 +4391,15 @@ impl Ast {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ast_parse_ffi(src: &CxxWString, flags: u8, errors: *mut ParseErrorListFfi) -> Box<Ast> {
|
fn ast_parse_ffi(src: &CxxWString, flags: u8, errors: *mut ParseErrorListFfi) -> Box<Ast> {
|
||||||
let mut out_errors: Option<ParseErrorList> = if errors.is_null() {
|
Box::new(Ast::parse(
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(unsafe { &(*errors).0 }.clone())
|
|
||||||
};
|
|
||||||
let ast = Box::new(Ast::parse(
|
|
||||||
src.as_wstr(),
|
src.as_wstr(),
|
||||||
ParseTreeFlags(flags),
|
ParseTreeFlags(flags),
|
||||||
&mut out_errors,
|
if errors.is_null() {
|
||||||
));
|
None
|
||||||
if let Some(out_errors) = out_errors {
|
} else {
|
||||||
unsafe { (*errors).0 = out_errors };
|
Some(unsafe { &mut (*errors).0 })
|
||||||
}
|
},
|
||||||
ast
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ast_parse_argument_list_ffi(
|
fn ast_parse_argument_list_ffi(
|
||||||
|
@ -4412,20 +4407,15 @@ fn ast_parse_argument_list_ffi(
|
||||||
flags: u8,
|
flags: u8,
|
||||||
errors: *mut ParseErrorListFfi,
|
errors: *mut ParseErrorListFfi,
|
||||||
) -> Box<Ast> {
|
) -> Box<Ast> {
|
||||||
let mut out_errors: Option<ParseErrorList> = if errors.is_null() {
|
Box::new(Ast::parse_argument_list(
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(unsafe { &(*errors).0 }.clone())
|
|
||||||
};
|
|
||||||
let ast = Box::new(Ast::parse_argument_list(
|
|
||||||
src.as_wstr(),
|
src.as_wstr(),
|
||||||
ParseTreeFlags(flags),
|
ParseTreeFlags(flags),
|
||||||
&mut out_errors,
|
if errors.is_null() {
|
||||||
));
|
None
|
||||||
if let Some(out_errors) = out_errors {
|
} else {
|
||||||
unsafe { (*errors).0 = out_errors };
|
Some(unsafe { &mut (*errors).0 })
|
||||||
}
|
},
|
||||||
ast
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_ast_traversal<'a>(root: &'a NodeFfi<'a>) -> Box<Traversal<'a>> {
|
fn new_ast_traversal<'a>(root: &'a NodeFfi<'a>) -> Box<Traversal<'a>> {
|
||||||
|
|
|
@ -120,7 +120,7 @@ pub type ParsedSourceRef = Option<Rc<ParsedSource>>;
|
||||||
pub fn parse_source(
|
pub fn parse_source(
|
||||||
src: WString,
|
src: WString,
|
||||||
flags: ParseTreeFlags,
|
flags: ParseTreeFlags,
|
||||||
errors: &mut Option<ParseErrorList>,
|
errors: Option<&mut ParseErrorList>,
|
||||||
) -> ParsedSourceRef {
|
) -> ParsedSourceRef {
|
||||||
let ast = Ast::parse(&src, flags, errors);
|
let ast = Ast::parse(&src, flags, errors);
|
||||||
if ast.errored() && !(flags & PARSE_FLAG_CONTINUE_AFTER_ERROR) {
|
if ast.errored() && !(flags & PARSE_FLAG_CONTINUE_AFTER_ERROR) {
|
||||||
|
@ -177,17 +177,15 @@ fn parse_source_ffi(
|
||||||
flags: u8,
|
flags: u8,
|
||||||
errors: *mut ParseErrorListFfi,
|
errors: *mut ParseErrorListFfi,
|
||||||
) -> Box<ParsedSourceRefFFI> {
|
) -> Box<ParsedSourceRefFFI> {
|
||||||
let mut out_errors: Option<ParseErrorList> = if errors.is_null() {
|
Box::new(ParsedSourceRefFFI(parse_source(
|
||||||
None
|
src.from_ffi(),
|
||||||
} else {
|
ParseTreeFlags(flags),
|
||||||
Some(unsafe { &(*errors).0 }.clone())
|
if errors.is_null() {
|
||||||
};
|
None
|
||||||
let ps = parse_source(src.from_ffi(), ParseTreeFlags(flags), &mut out_errors);
|
} else {
|
||||||
if let Some(out_errors) = out_errors {
|
Some(unsafe { &mut (*errors).0 })
|
||||||
unsafe { (*errors).0 = out_errors };
|
},
|
||||||
}
|
)))
|
||||||
|
|
||||||
Box::new(ParsedSourceRefFFI(ps))
|
|
||||||
}
|
}
|
||||||
impl ParsedSourceRefFFI {
|
impl ParsedSourceRefFFI {
|
||||||
fn clone(&self) -> Box<ParsedSourceRefFFI> {
|
fn clone(&self) -> Box<ParsedSourceRefFFI> {
|
||||||
|
|
Loading…
Reference in a new issue