Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
language-lua - Lua 5.2 lexer, parser and pretty-printer | ||
------------------------------------------------------- | ||
|
||
This package is just like any other *language x* packages. It provides lexer, parser and pretty-printer for [Lua](http://www.lua.org/) programming language. | ||
|
||
### Usage | ||
|
||
This module provides 3 parsers. | ||
|
||
- `chunk`: Lua file parser. | ||
- `exp`: Lua expression parser. | ||
- `stat`: Lua statement parser. | ||
|
||
Lexing is needed before running a parser. `parseText` function runs lexer before parsing. So if you want to parse a Lua expression, you can call `parseText exp string`, where string is the Lua expression to parse. | ||
|
||
`parseFile` is a helper to parse Lua files. Example: `parseFile "/path/to/lua/file"`. This is same as `readFile path >>= return . parseText chunk`. | ||
|
||
Note that `parseText` may result with failure, so it's return type is `Either ParserError a`. | ||
|
||
### Lexer | ||
|
||
Lexer is not exported by top-level Language.Lua module. You need to import `Language.Lua.Lexer`. After that, `llex string` scans the string and returns token list. Tokens are defined in `Language.Lua.Token`. | ||
|
||
### Pretty-printer | ||
|
||
Pretty-printer is still under development, and subject to lots of changes. It works, but lots of functionality will be added. | ||
|
||
For now, you can use `pprint syntax_tree` to pretty-print a Lua syntax tree. |