Skip to content

dzavalishin/lua-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-parser

A Lua 5.2 parser and AST walker using ANTLR 3.

The grammar can be found in src/main/antlr3/nl/bigo/luaparser.

Seeing the generated parser in action can be done by building a fat JAR of the project and then running it to parse a Lua file.

Get started

1. clone this repository

git clone https://github.com/bkiers/lua-parser
cd lua-parser

2. generate the lexer and parser classes and build a fat JAR

mvn clean install package

3. parse a Lua file

java -jar target/lua-parser-0.1.0.jar src/main/lua/test.lua

which would print:

Parsing `src/main/lua/test.lua`...

'- CHUNK
   '- ASSIGNMENT
      |- VAR_LIST
      |  '- Name='uniqueid_some_event'
      '- EXPR_LIST
         '- FUNCTION
            |- PARAM_LIST
            |  '- Name='e'
            '- CHUNK
               |- If='if'
               |  '- CONDITION
               |     |- VAR
               |     |  |- Name='e'
               |     |  |- INDEX
               |     |  |  '- String='HasString'
               |     |  '- COL_CALL
               |     |     '- String='string1'
               |     '- CHUNK
               '- If='if'
                  '- CONDITION
                     |- VAR
                     |  |- Name='e'
                     |  |- INDEX
                     |  |  '- String='HasString'
                     |  '- COL_CALL
                     |     '- String='string2'
                     '- CHUNK

> from Lua52Walker.assignment
>   VAR_LIST=uniqueid_some_event
>   EXPR_LIST=FUNCTION

given that the file src/main/lua/test.lua contains:

function uniqueid_some_event (e)
  if (e:HasString("string1")) then
    -- do something
  end 
  if(e:HasString("string2")) then
    -- do something
  end
end

About

A Lua 5.2 parser and AST walker using ANTLR 3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • GAP 80.5%
  • Java 18.7%
  • Lua 0.8%