diff options
author | Robert Alessi <alessi@robertalessi.net> | 2018-06-02 16:55:55 +0200 |
---|---|---|
committer | Robert Alessi <alessi@robertalessi.net> | 2018-06-02 16:55:55 +0200 |
commit | bc16279db68fd63aa1830167e0a635f6526cc1ed (patch) | |
tree | b999178104c1c22976b022f4f6f2972916b69a0a | |
parent | 959ecb27586c882d75d5b8c2dd5e489e5508af49 (diff) | |
download | arabluatex-bc16279db68fd63aa1830167e0a635f6526cc1ed.tar.gz |
use LPeg patterns in holdcmd() as well and get rid of (un)protectarb()
-rw-r--r-- | arabluatex.lua | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/arabluatex.lua b/arabluatex.lua index 8ba42fd..053fb50 100644 --- a/arabluatex.lua +++ b/arabluatex.lua | |||
@@ -35,21 +35,21 @@ local function gsub(s, patt, repl) | |||
35 | end | 35 | end |
36 | 36 | ||
37 | local function protectarb(str) | 37 | local function protectarb(str) |
38 | str = string.gsub(str, "(\\arb.?)(%[.-%])(%b{})", "\\@arb%2%3") | 38 | -- str = string.gsub(str, "(\\arb%s?)(%[.-%])(%b{})", "\\@arb%2%3") |
39 | str = string.gsub(str, "(\\begin.?)(%b{})(%b[])", "\\@@begin{%2%3}") | 39 | -- str = string.gsub(str, "(\\begin%s?)(%b{})(%b[])", "\\@@begin{%2%3}") |
40 | str = string.gsub(str, "(\\begin.?)(%b{})", "\\@begin%2") | 40 | -- str = string.gsub(str, "(\\begin%s?)(%b{})", "\\@begin%2") |
41 | str = string.gsub(str, "(\\end.?)(%b{})", "\\@end%2") | 41 | -- str = string.gsub(str, "(\\end%s?)(%b{})", "\\@end%2") |
42 | str = string.gsub(str, "\\par", "\\p@r{}") | 42 | -- str = string.gsub(str, "\\par", "\\p@r{}") |
43 | str = string.gsub(str, "\\@@par", "\\p@r{}") | 43 | -- str = string.gsub(str, "\\@@par", "\\p@r{}") |
44 | return str | 44 | return str |
45 | end | 45 | end |
46 | 46 | ||
47 | local function unprotectarb(str) | 47 | local function unprotectarb(str) |
48 | str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3") | 48 | -- str = string.gsub(str, "(\\@arb)(%[.-%])(%b{})", "\\arb%2%3") |
49 | str = string.gsub(str, "(\\@@begin){(%b{})(%b[])}", "\\begin%2%3") | 49 | -- str = string.gsub(str, "(\\@@begin){(%b{})(%b[])}", "\\begin%2%3") |
50 | str = string.gsub(str, "(\\@begin)(%b{})", "\\begin%2") | 50 | -- str = string.gsub(str, "(\\@begin)(%b{})", "\\begin%2") |
51 | str = string.gsub(str, "(\\@end)(%b{})", "\\end%2") | 51 | -- str = string.gsub(str, "(\\@end)(%b{})", "\\end%2") |
52 | str = string.gsub(str, "\\p@r{}", "\\par") | 52 | -- str = string.gsub(str, "\\p@r{}", "\\par") |
53 | return str | 53 | return str |
54 | end | 54 | end |
55 | 55 | ||
@@ -57,6 +57,11 @@ end | |||
57 | -- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is | 57 | -- arabluatex. 'albrkcmds' is what is set by default. 'brkcmds' is |
58 | -- what may be set in the preamble as argument of \MkArbBreak{} | 58 | -- what may be set in the preamble as argument of \MkArbBreak{} |
59 | local albrkcmds = { | 59 | local albrkcmds = { |
60 | "arb", | ||
61 | "begin", | ||
62 | "end", | ||
63 | "par", | ||
64 | "@@par", | ||
60 | "RL", | 65 | "RL", |
61 | "LR", | 66 | "LR", |
62 | "RLfootnote", | 67 | "RLfootnote", |
@@ -90,7 +95,7 @@ local bcbraces = lpeg.Cs{ "{" * ((1 - lpeg.S"{}") + lpeg.V(1))^0 * "}" } | |||
90 | local spce = lpeg.Cs(" ") | 95 | local spce = lpeg.Cs(" ") |
91 | local bsqbracketsii = lpeg.Cs(bsqbrackets^-2) | 96 | local bsqbracketsii = lpeg.Cs(bsqbrackets^-2) |
92 | local bcbracesii = lpeg.Cs(bcbraces^-2) | 97 | local bcbracesii = lpeg.Cs(bcbraces^-2) |
93 | local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii) | 98 | local cmdargs = lpeg.Cs(spce * bsqbracketsii * bcbracesii * bsqbrackets^-1) |
94 | 99 | ||
95 | local function breakcmd(str) | 100 | local function breakcmd(str) |
96 | -- process \item[], then \item[] | 101 | -- process \item[], then \item[] |
@@ -133,11 +138,11 @@ local function holdcmd(str) | |||
133 | body = string.sub(body, 2, -2) | 138 | body = string.sub(body, 2, -2) |
134 | body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody) | 139 | body = string.gsub(body, "\\(.-)(%b{})", function(btag, bbody) |
135 | bbody = string.sub(bbody, 2, -2) | 140 | bbody = string.sub(bbody, 2, -2) |
136 | if string.find(btag, "@") then | 141 | -- if string.find(btag, "@") then |
137 | return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody)) | 142 | -- return holdcmd(string.format("}\\%s{%s}\\arb{", btag, bbody)) |
138 | else | 143 | -- else |
139 | return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody)) | 144 | return holdcmd(string.format("}\\%s{\\arb{%s}}\\arb{", btag, bbody)) |
140 | end | 145 | -- end |
141 | end) | 146 | end) |
142 | return string.format("\\%s{%s}", tag, body) | 147 | return string.format("\\%s{%s}", tag, body) |
143 | end) | 148 | end) |
@@ -589,7 +594,7 @@ function processvoc(str, rules, scheme) | |||
589 | str = "\\arb{".. str.."}" | 594 | str = "\\arb{".. str.."}" |
590 | str = processarbnull(str, scheme) | 595 | str = processarbnull(str, scheme) |
591 | str = takeoutcapetc(str) | 596 | str = takeoutcapetc(str) |
592 | str = protectarb(str) | 597 | -- str = protectarb(str) |
593 | str = breakcmd(str) | 598 | str = breakcmd(str) |
594 | str = holdcmd(str) | 599 | str = holdcmd(str) |
595 | if scheme == "buckwalter" then | 600 | if scheme == "buckwalter" then |
@@ -600,7 +605,7 @@ function processvoc(str, rules, scheme) | |||
600 | elseif rules == "dflt" or rules == "idgham" then | 605 | elseif rules == "dflt" or rules == "idgham" then |
601 | str = voc(str, rules) | 606 | str = voc(str, rules) |
602 | else end | 607 | else end |
603 | str = unprotectarb(str) | 608 | -- str = unprotectarb(str) |
604 | return str | 609 | return str |
605 | end | 610 | end |
606 | 611 | ||
@@ -608,7 +613,7 @@ function processfullvoc(str, rules, scheme) | |||
608 | str = "\\arb{".. str.."}" | 613 | str = "\\arb{".. str.."}" |
609 | str = processarbnull(str, scheme) | 614 | str = processarbnull(str, scheme) |
610 | str = takeoutcapetc(str) | 615 | str = takeoutcapetc(str) |
611 | str = protectarb(str) | 616 | -- str = protectarb(str) |
612 | str = breakcmd(str) | 617 | str = breakcmd(str) |
613 | str = holdcmd(str) | 618 | str = holdcmd(str) |
614 | if scheme == "buckwalter" then | 619 | if scheme == "buckwalter" then |
@@ -621,7 +626,7 @@ function processfullvoc(str, rules, scheme) | |||
621 | elseif rules == "dflt" or rules == "idgham" then | 626 | elseif rules == "dflt" or rules == "idgham" then |
622 | str = fullvoc(str, rules) | 627 | str = fullvoc(str, rules) |
623 | else end | 628 | else end |
624 | str = unprotectarb(str) | 629 | -- str = unprotectarb(str) |
625 | return str | 630 | return str |
626 | end | 631 | end |
627 | 632 | ||
@@ -629,7 +634,7 @@ function processnovoc(str, rules, scheme) | |||
629 | str = "\\arb{".. str.."}" | 634 | str = "\\arb{".. str.."}" |
630 | str = processarbnull(str, scheme) | 635 | str = processarbnull(str, scheme) |
631 | str = takeoutcapetc(str) | 636 | str = takeoutcapetc(str) |
632 | str = protectarb(str) | 637 | -- str = protectarb(str) |
633 | str = breakcmd(str) | 638 | str = breakcmd(str) |
634 | str = holdcmd(str) | 639 | str = holdcmd(str) |
635 | if scheme == "buckwalter" then | 640 | if scheme == "buckwalter" then |
@@ -640,7 +645,7 @@ function processnovoc(str, rules, scheme) | |||
640 | elseif rules == "dflt" or rules == "idgham" then | 645 | elseif rules == "dflt" or rules == "idgham" then |
641 | str = novoc(str) | 646 | str = novoc(str) |
642 | else end | 647 | else end |
643 | str = unprotectarb(str) | 648 | -- str = unprotectarb(str) |
644 | return str | 649 | return str |
645 | end | 650 | end |
646 | 651 | ||
@@ -649,7 +654,7 @@ function processtrans(str, mode, rules, scheme) | |||
649 | str = processdiscretionary(str) | 654 | str = processdiscretionary(str) |
650 | str = processarbnull(str, scheme) | 655 | str = processarbnull(str, scheme) |
651 | str = takeoutabjad(str) | 656 | str = takeoutabjad(str) |
652 | str = protectarb(str) | 657 | -- str = protectarb(str) |
653 | str = breakcmd(str) | 658 | str = breakcmd(str) |
654 | str = holdcmd(str) | 659 | str = holdcmd(str) |
655 | if scheme == "buckwalter" then | 660 | if scheme == "buckwalter" then |
@@ -662,7 +667,7 @@ function processtrans(str, mode, rules, scheme) | |||
662 | elseif mode == "arabica" then | 667 | elseif mode == "arabica" then |
663 | str = transarabica(str) | 668 | str = transarabica(str) |
664 | end | 669 | end |
665 | str = unprotectarb(str) | 670 | -- str = unprotectarb(str) |
666 | return str | 671 | return str |
667 | end | 672 | end |
668 | 673 | ||