pub fn is_single_expression(out: &ParseOutput) -> boolExpand description
Whether the parsed text is exactly one complete R expression, the way R’s
own parser judges it — the predicate behind rlang::parse_expr() (and so
roxygen2’s can_parse()).
This takes the whole ParseOutput rather than just the CST because a
recovered tree alone cannot answer the question: f( yields a well-shaped
CALL_EXPR and reports the missing ) only as a diagnostic.
Three things have to hold:
- the parse is diagnostic-free;
- the root holds one expression, optionally followed by a single
;. R’s;is a statement terminator, not a separator that may stand alone: it must follow an expression on the same line, and a second one opens an empty statement, which is a syntax error (x;parses,;x,x;;,x\n;andx; ydo not); - no name in the tree is one R’s lexer rejects but arity’s accepts (see
has_r_invalid_name).