stevenjohnstone / lua-grammar

ANTLRv4 lexer and parser grammars for Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ANTLRv4 Lua parser and lexer grammars

Modified https://github.com/antlr/grammars-v4/tree/master/lua:

  • split lexer and parser grammars
  • added more statement types (varstat etc)
  • added a COMMENTS channel
  • whitespace goes to HIDDEN channel rather than simply skipping

Usage

As for other ANTLRv4 grammars:

antlr4 LuaLexer.g4 LuaParser.g4

Railroad Diagrams

See the grammar in the form of railroad diagrams here.

Examples

Generating a Callgraph

The following is a callgraph for inspect.lua:

callgraph.

On Linux with clang, graphviz and antlr4 installed:

cd examples/cpp/dot
make

Then

 wget -q https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua -O -|./callgraph |dot -T png -o inspect.png

Dependency graph

The following is an attempt at a dependency graph for Luarocks, as installed on my system:

dependency

On Linux with clang, graphviz and antlr4 installed:

cd examples/cpp/deps
make

Then

./deps /usr/bin/luarocks | neato -T png -o deps.png

About

ANTLRv4 lexer and parser grammars for Lua


Languages

Language:Go 96.4%Language:ANTLR 3.6%