Skip to content

Commit

Permalink
Add a configurable reader and writer to the Alfons integration
Browse files Browse the repository at this point in the history
  • Loading branch information
daelvn committed Oct 7, 2024
1 parent f73dc47 commit 24a10e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.lua linguist-generated
*.rockspec linguist-generated
*.mp linguist-language=MoonScript
docs/* linguist-documentation
*.yue linguist-language=MoonScript
docs/* linguist-documentation
17 changes: 11 additions & 6 deletions alfons/tasks/fir.yue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ tasks:
fir: =>
import 'fir.version' as FIR_VERSION
prints "%{bold blue}Fir #{FIR_VERSION} (in Alfons mode)"

-- set reader/writer
@reader or= readfile
@writer or= writefile

-- arrow
printArrow = (txt) -> prints "%{blue}==>%{white} #{txt}" unless @s or @silent
printError = (txt) -> prints "%{red}#{txt}" unless @s or @silent
printPlus = (txt) -> prints "%{green}+ #{txt}" unless @s or @silent
printMini = (txt) -> prints "%{yellow}-> #{txt}" unless @s or @silent

-- mkdir
mkdirFor = (path) ->
mkdirFor = (_path) ->
_path = _path\match "(.+)/.-"
sep, pStr = fsinfo.sep, ""
for dir in path\gmatch "[^" .. sep .. "]+" do
for dir in _path\gmatch "[^" .. sep .. "]+" do
pStr = pStr .. dir .. sep
fs.mkdir pStr
-- fromGlob reimplementation
Expand Down Expand Up @@ -55,9 +60,9 @@ tasks:
doIgnore = true if node\match ig
-- add file
unless doIgnore
fname = (fspath.abs node)\match "#{cwd}#{fsinfo.sep}(.+)"
fname = (path.abs node)\match "#{cwd}#{fsinfo.sep}(.+)"
if inp.verbatim
emitted[fname] = readfile fname
emitted[fname] = @.reader fname
else
files[] = fname
printPlus fname
Expand All @@ -71,7 +76,7 @@ tasks:
extracted = {}
for file in *files
--printMini file
extracted[file] = (readfile file) |> extract _, @config.language, @config.backend or {}
extracted[file] = (@.reader file) |> extract _, @config.language, @config.backend or {}
--- parse comments ---
import parse from require "fir.generic.parser"
--printArrow "Parsing comments"
Expand Down Expand Up @@ -121,4 +126,4 @@ tasks:
--printMini file
--
mkdirFor file
writefile file, content
@.writer file, content

0 comments on commit 24a10e7

Please sign in to comment.