aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/compile_doc.yue
blob: 64d7d406e4e898e2f7418eda64c5883147990304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
outputFolder = ...
for [compiledFile, docFile] in *[
		["codes_from_doc.lua", "doc/docs/doc/README.md"]
		["codes_from_doc_zh.lua", "doc/docs/zh/doc/README.md"]
	]
	close input = with? io.open docFile
		import "yue" as :to_lua
		text = \read "*a"
		codes = []
		for code in text\gmatch "```moonscript(.-)```"
			if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false
				codes[] = result
			elseif not err\match "macro exporting module only accepts macro definition"
				print err
				os.exit 1
		for code in text\gmatch "<pre>(.-)</pre>"
			if result, err := to_lua code\gsub("&lt;", "<")\gsub("&gt;", ">"), implicit_return_root: false, reserve_line_number: false
				codes[] = result
			else
				print err
				os.exit 1
		close output = with io.open "#{outputFolder}/#{compiledFile}", "w+"
			\write table.concat codes