Skip to content

Commit bf16c51

Browse files
committed
add docs for syntax tranformer
1 parent dd2d041 commit bf16c51

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/command_line.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ compiled automatically.
130130

131131
A full list of flags can be seen by passing the `-h` or `--help` flag.
132132

133+
### Syntax Transformer
134+
135+
A syntax transformer is a function that manipulates MoonScript code before
136+
compiling to Lua. It operates on the parsed AST (Abstract Syntax Tree). It can
137+
be used to implement macros, change syntax, optimize code, among other things.
138+
You specify the name of a Lua module. This module must return a single function
139+
(or callable object) that takes AST as an argument, and returns the new AST.
140+
141+
```bash
142+
moonc --transform my_transfomer my_script.moon
143+
```
144+
145+
The transform can fail by returning `nil` and an error message. MoonScript AST
146+
is currently undocumented, so you'll have to experiment by printing out the AST
147+
to see how to make changes. MoonScript AST is made up of standard Lua tables
148+
that are nested.
149+
133150
### Linter
134151

135152
`moonc` contains a [lint][1] tool for statically detecting potential problems

0 commit comments

Comments
 (0)