Giter VIP home page Giter VIP logo

lua-parser's Introduction

lua-parser

A Lua 5.3 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

lua-parser's People

Contributors

bkiers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lua-parser's Issues

Could you do Lua 5.3?

I need a Lua 5.3 parser in Java, but haven't been able to find one. I'd love to do it myself, but I'm not too good with this stuff. AFAIK the only syntax differences are only a few new operators:

  • x ~ y (bitwise xor)
  • ~x
  • x | y
  • x & y
  • x << y
  • x >> y
  • x // y (floor division)

Could you do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.