Skip to content

Commit

Permalink
docs: update English translation [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
stone-zeng committed Apr 3, 2018
1 parent 6666727 commit c01aa6a
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 150 deletions.
83 changes: 38 additions & 45 deletions scripts/get-doc-en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ local file_banner = "%%\n"
local tag_preamble_str = "\\preamble"
local tag_endpreamble_str = "\\endpreamble"

local tag_driver_begin_str = "%<*driver>"
local tag_driver_end_str = "%</driver>"

local tag_inline_str = "%^^A!"
local tag_begin_str = "%^^A+"
local tag_end_str = "%^^A-"
local tag_str_len = string.len(tag_inline_str)

local latex_ex_str = "\\begin{latexexample}["
local shell_ex_str = "\\begin{shellexample}["
local syntax_str = " \\begin{fdusyntax}["

local latex_ex_str_len = string.len(latex_ex_str)
local shell_ex_str_len = string.len(shell_ex_str)
local syntax_str_len = string.len(syntax_str)

local function test_tag(str, tag)
if string.sub(str, 1, string.len(tag)) == tag then
return true
Expand All @@ -42,36 +37,16 @@ local function remove_normal_space(str)
return string.sub(str, 3)
end

local function add_lst_gobble(str)
if string.sub(str, 1, latex_ex_str_len) == latex_ex_str then
return latex_ex_str .. "gobble=1," ..
string.sub(str, latex_ex_str_len + 1)
end
if string.sub(str, 1, shell_ex_str_len) == shell_ex_str then
return shell_ex_str .. "gobble=1," ..
string.sub(str, shell_ex_str_len + 1)
end
if string.sub(str, 1, syntax_str_len) == syntax_str then
return syntax_str .. "gobble=4," ..
string.sub(str, syntax_str_len + 1)
end
return str
end

local function process_preamble_line(str)
return "%% " .. str
end

local function process_verbatim_line(str)
str = remove_normal_space(str)
str = add_lst_gobble(str)
return str
return remove_normal_space(str)
end

local function process_normal_line(str)
str = string.sub(str, tag_str_len + 2)
str = add_lst_gobble(str)
return str
return string.sub(str, tag_str_len + 2)
end

----------------------
Expand All @@ -84,6 +59,9 @@ output_file = io.open(output_file_name, "w")
-- Test whether it's in the preamble.
preamble_flag = 0

-- Test whether it's in the driver part.
driver_flag = 0

-- Test whether it's in the verbatim environment.
inside_flag = 0

Expand All @@ -96,22 +74,37 @@ for line in input_file:lines() do
elseif test_tag(line, tag_endpreamble_str) then
preamble_flag = preamble_flag - 1
else
-- If beginning with `%^^A+` or `%^^A-`, then increase or
-- decrease the flag, in order to determine the start or end
-- position of verbatim.
if test_tag(line, tag_begin_str) then
inside_flag = inside_flag + 1
elseif test_tag(line, tag_end_str) then
inside_flag = inside_flag - 1
-- Check if in the driver part.
if test_tag(line, tag_driver_begin_str) then
driver_flag = driver_flag + 1
elseif test_tag(line, tag_driver_end_str) then
driver_flag = driver_flag - 1
else
if preamble_flag == 1 then
output_file:write(process_preamble_line(line), "\n")
-- If flag = 1, then it's a verbatim environment.
elseif inside_flag == 1 then
output_file:write(process_verbatim_line(line), "\n")
-- If beginning with `%^^A!`, then this line is normal text.
elseif test_tag(line, tag_inline_str) then
output_file:write(process_normal_line(line), "\n")
-- If beginning with `%^^A+` or `%^^A-`, then increase or
-- decrease the flag, in order to determine the start or end
-- position of verbatim.
if test_tag(line, tag_begin_str) then
inside_flag = inside_flag + 1
elseif test_tag(line, tag_end_str) then
inside_flag = inside_flag - 1
else
if preamble_flag == 1 then
output_file:write(process_preamble_line(line), "\n")
elseif driver_flag == 1 then
-- Inside <*driver> ... </driver>.
-- Similar to normal text but do not have `% ` at beginning.
if inside_flag == 1 then
output_file:write(line, "\n")
elseif test_tag(line, tag_inline_str) then
output_file:write(process_normal_line(line), "\n")
end
elseif inside_flag == 1 then
-- If inside_flag = 1, then it's a verbatim environment.
output_file:write(process_verbatim_line(line), "\n")
elseif test_tag(line, tag_inline_str) then
-- If beginning with `%^^A!`, then this line is normal text.
output_file:write(process_normal_line(line), "\n")
end
end
end
end
Expand Down
Loading

0 comments on commit c01aa6a

Please sign in to comment.