-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(outputters): Promote pseudo AST backend to full-blow outputter
This also comes with the ability for *any* outputter to pre-process the AST tree if it wanted to (e.g. for remove leaf types it would not be able to output. If the outputter doesn't do anything to the AST it is just a pass-through step. Note this does *not* yet walk the AST and do any AST munging that functions might engage in, it only catches the top level tree as parsed by the inputter. Additionally it is not a full serialization of the AST that could be read back in with an input driver. We'd need a new dependency on something like serpent for that, which would be a lovely next step.
- Loading branch information
Showing
4 changed files
with
36 additions
and
10 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
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
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,27 @@ | ||
local base = require("outputters.base") | ||
|
||
local outputter = pl.class(base) | ||
outputter._name = "ast" | ||
outputter.extension = "ast" | ||
|
||
local outfile | ||
|
||
function outputter:_ensureInit () | ||
if not outfile then | ||
local fname = self:getOutputFilename() | ||
outfile = fname == "-" and io.stdout or io.open(fname, "w+") | ||
end | ||
end | ||
|
||
function outputter:preProcess (ast) | ||
self:_ensureInit() | ||
local prettyprinted = pl.pretty.write(ast, " ") | ||
outfile:write(prettyprinted) | ||
end | ||
|
||
function outputter:finish () | ||
self:runHooks("prefinish") | ||
outfile:close() | ||
end | ||
|
||
return outputter |
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