summaryrefslogtreecommitdiff
path: root/spec/outputs/compile_doc.lua
blob: f661bbd4066cce7d522a17d888dfe7219e482ce8 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
local outputFolder, docFolder
do
	local _obj_0 = {
		...
	}
	outputFolder, docFolder = _obj_0[1], _obj_0[2]
end
local getFiles
getFiles = function(locale)
	if locale == "en" then
		locale = ""
	else
		locale = tostring(locale) .. "/"
	end
	return {
		"doc/docs/" .. tostring(locale) .. "doc/index.md",
		"doc/docs/" .. tostring(locale) .. "doc/advanced/do.md",
		"doc/docs/" .. tostring(locale) .. "doc/advanced/line-decorators.md",
		"doc/docs/" .. tostring(locale) .. "doc/advanced/macro.md",
		"doc/docs/" .. tostring(locale) .. "doc/advanced/try.md",
		"doc/docs/" .. tostring(locale) .. "doc/data-structures/table-literals.md",
		"doc/docs/" .. tostring(locale) .. "doc/data-structures/comprehensions.md",
		"doc/docs/" .. tostring(locale) .. "doc/objects/object-oriented-programming.md",
		"doc/docs/" .. tostring(locale) .. "doc/objects/with-statement.md",
		"doc/docs/" .. tostring(locale) .. "doc/assignment/assignment.md",
		"doc/docs/" .. tostring(locale) .. "doc/assignment/varargs-assignment.md",
		"doc/docs/" .. tostring(locale) .. "doc/assignment/if-assignment.md",
		"doc/docs/" .. tostring(locale) .. "doc/assignment/destructuring-assignment.md",
		"doc/docs/" .. tostring(locale) .. "doc/assignment/the-using-clause-controlling-destructive-assignment.md",
		"doc/docs/" .. tostring(locale) .. "doc/getting-started/usage.md",
		"doc/docs/" .. tostring(locale) .. "doc/getting-started/introduction.md",
		"doc/docs/" .. tostring(locale) .. "doc/getting-started/installation.md",
		"doc/docs/" .. tostring(locale) .. "doc/control-flow/conditionals.md",
		"doc/docs/" .. tostring(locale) .. "doc/control-flow/for-loop.md",
		"doc/docs/" .. tostring(locale) .. "doc/control-flow/continue.md",
		"doc/docs/" .. tostring(locale) .. "doc/control-flow/switch.md",
		"doc/docs/" .. tostring(locale) .. "doc/control-flow/while-loop.md",
		"doc/docs/" .. tostring(locale) .. "doc/functions/function-stubs.md",
		"doc/docs/" .. tostring(locale) .. "doc/functions/backcalls.md",
		"doc/docs/" .. tostring(locale) .. "doc/functions/function-literals.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/whitespace.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/comment.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/attributes.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/operator.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/literals.md",
		"doc/docs/" .. tostring(locale) .. "doc/language-basics/module.md",
		"doc/docs/" .. tostring(locale) .. "doc/reference/license-mit.md",
		"doc/docs/" .. tostring(locale) .. "doc/reference/the-yuescript-library.md"
	}
end
local docs
do
	local _accum_0 = { }
	local _len_0 = 1
	local _list_0 = {
		"en",
		"zh",
		"pt-br",
		"de",
		"id-id"
	}
	for _index_0 = 1, #_list_0 do
		local locale = _list_0[_index_0]
		_accum_0[_len_0] = {
			"codes_from_doc_" .. tostring(locale) .. ".lua",
			"yue-" .. tostring(locale) .. ".md",
			getFiles(locale)
		}
		_len_0 = _len_0 + 1
	end
	docs = _accum_0
end
for _index_0 = 1, #docs do
	local _des_0 = docs[_index_0]
	local compiledFile, docFile, docFiles = _des_0[1], _des_0[2], _des_0[3]
	local codes = { }
	local docTexts = { }
	for _index_1 = 1, #docFiles do
		local docFile = docFiles[_index_1]
		local input
		local _with_0 = io.open(docFile)
		if _with_0 ~= nil then
			local to_lua = require("yue").to_lua
			local text = _with_0:read("*a")
			docTexts[#docTexts + 1] = text
			for code in text:gmatch("```yuescript[\r\n]+(.-)```[^%w]") do
				local result, err = to_lua(code, {
					implicit_return_root = false,
					reserve_line_number = false
				})
				if result then
					codes[#codes + 1] = result
				elseif not err:match("macro exporting module only accepts macro definition") then
					print(err)
					os.exit(1)
				end
			end
			for code in text:gmatch("```yue[\r\n]+(.-)```[^%w]") do
				local result, err = to_lua(code, {
					implicit_return_root = false,
					reserve_line_number = false
				})
				if result then
					codes[#codes + 1] = result
				else
					print(err)
					os.exit(1)
				end
			end
		end
		input = _with_0
		local _close_0 <close> = input
	end
	local output
	do
		local _with_0 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+")
		_with_0:write(table.concat(codes))
		output = _with_0
	end
	local _close_0 <close> = output
	local output2
	local _with_0 = io.open(tostring(docFolder) .. "/" .. tostring(docFile), "w+")
	_with_0:write(table.concat(docTexts, "\n"))
	output2 = _with_0
	local _close_1 <close> = output2
end