Skip to content

loose parsing of Lua code, ignoring syntax errors

Notifications You must be signed in to change notification settings

tst2005/lua-parser-loose

Repository files navigation

DESCRIPTION

  lua_parser_loose

  Does loose parsing of Lua code.
  If the code has syntax errors, the parse does not abort; rather,
  some information (e.g. local and global variable scopes) is still inferred.
  This may be useful for code interactively typed into a text editor.
  
  This includes as an example of expanding Lua 5.2
  code to Lua 5.1 code with explicit _ENV variables.  Example:
 
    "function f(_ENV, x) print(x, y)" -->
    "function _ENV.f(_ENV, x) _ENV.print(x, _ENV.y) end"

  Characteristics of this code:
  - Does not construct any AST but rather streams tokens.
    Should be memory and space efficient on large files.
  - Very loose parsing.
    Should work on broken code, such as that being interactively typed into
    a text editor.
  - Loose parsing makes this code somewhat hard to validate its correctness,
    but tests are performed to verify robustness.
    An alternative choice would be use to the strict Metalua parser (easier).
  - The parsing code is designed so that parts of it may be reused for other
    purposes in other projects.

  Language notes:
  
  - The deprecated Lua 5.0 "arg" variable representing variable
    arguments (...) in a function is not specially recognized.

STABILITY

  This is fairly well tested, but the code is new and might still have errors.
  Standard tests are performed in "test/test.lua".
  More extensive tests are in "test/test_luac.lua", which validates the
  parser's local/global variable detection against the luac bytecode
  output listings.  test_luac.lua has been performed against the entire
  LuaDist source code repository (about 2700 .lua files), or at least the
  Lua files in it having no syntax errors.

DEPENDENCIES/INSTALLATION
   
  Requires Lua libraries in the Metalua "refactoring" branch (2013-04-09).
  To obtain this, do this in the root directory of this project:
     git clone -b repackaging https://github.com/fab13n/metalua.git
  No need to "make install".
  
  To test, just run "lua example.lua".

COPYRIGHT

  See COPYRIGHT.
  (c) 2013 David Manura.  MIT License (same as Lua 5.1).  2013-04

About

loose parsing of Lua code, ignoring syntax errors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%