aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/compile_doc.yue
blob: 20f68dfe9cd08ce07622ef35e0a9a62e338f4b82 (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
outputFolder = ...

getFiles = (locale) ->
	locale = if locale == "en" then "" else "#{locale}/"
	[
		"doc/docs/#{locale}doc/index.md"
		"doc/docs/#{locale}doc/advanced/do.md"
		"doc/docs/#{locale}doc/advanced/line-decorators.md"
		"doc/docs/#{locale}doc/advanced/macro.md"
		"doc/docs/#{locale}doc/advanced/module.md"
		"doc/docs/#{locale}doc/advanced/try.md"
		"doc/docs/#{locale}doc/data-structures/table-literals.md"
		"doc/docs/#{locale}doc/data-structures/comprehensions.md"
		"doc/docs/#{locale}doc/objects/object-oriented-programming.md"
		"doc/docs/#{locale}doc/objects/with-statement.md"
		"doc/docs/#{locale}doc/assignment/assignment.md"
		"doc/docs/#{locale}doc/assignment/varargs-assignment.md"
		"doc/docs/#{locale}doc/assignment/if-assignment.md"
		"doc/docs/#{locale}doc/assignment/destructuring-assignment.md"
		"doc/docs/#{locale}doc/assignment/the-using-clause-controlling-destructive-assignment.md"
		"doc/docs/#{locale}doc/getting-started/usage.md"
		"doc/docs/#{locale}doc/getting-started/introduction.md"
		"doc/docs/#{locale}doc/getting-started/installation.md"
		"doc/docs/#{locale}doc/control-flow/conditionals.md"
		"doc/docs/#{locale}doc/control-flow/for-loop.md"
		"doc/docs/#{locale}doc/control-flow/continue.md"
		"doc/docs/#{locale}doc/control-flow/switch.md"
		"doc/docs/#{locale}doc/control-flow/while-loop.md"
		"doc/docs/#{locale}doc/functions/function-stubs.md"
		"doc/docs/#{locale}doc/functions/backcalls.md"
		"doc/docs/#{locale}doc/functions/function-literals.md"
		"doc/docs/#{locale}doc/language-basics/whitespace.md"
		"doc/docs/#{locale}doc/language-basics/comment.md"
		"doc/docs/#{locale}doc/language-basics/attributes.md"
		"doc/docs/#{locale}doc/language-basics/operator.md"
		"doc/docs/#{locale}doc/language-basics/literals.md"
		"doc/docs/#{locale}doc/reference/license-mit.md"
		"doc/docs/#{locale}doc/reference/the-yuescript-library.md"
	]
docs = [ ["codes_from_doc_#{locale}.lua", getFiles locale] for locale in *["en", "zh", "pt-br", "de", "id-id"]]
for [compiledFile, docFiles] in *docs
	codes = []
	for docFile in *docFiles
		close input = with? io.open docFile
			import "yue" as :to_lua
			text = \read "*a"
			for code in text\gmatch "```yuescript[\r\n]+(.-)```[^%w]"
				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 "```yue[\r\n]+(.-)```[^%w]"
				if result, err := to_lua code, 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