full_moon

Function parse_fallible

source
pub fn parse_fallible(code: &str, lua_version: LuaVersion) -> AstResult
Expand description

Given code and a pinned Lua version, will produce an ast::AstResult. This AstResult always produces some Ast, regardless of errors. If a partial Ast is produced (i.e. if there are any errors), a few guarantees are lost:

  1. Tokens may be produced that aren’t in the code itself. For example, if x == 2 code() will produce a phantom then token in order to produce a usable If struct. These phantom tokens will have a null position. If you need accurate positions from the phantom tokens, you can call Ast::update_positions.
  2. The code, when printed, is not guaranteed to be valid Lua. This can happen in the case of something like local x = if, which will produce a LocalAssignment that would print to local x =.
  3. There are no stability guarantees for partial Ast results, but they are consistent within the same exact version of full-moon.