Skip to content

Commit

Permalink
[Soros] fix right boundary inheritance in conditional text
Browse files Browse the repository at this point in the history
Conditional text didn't support boundary inheritance,
treated always as boundary (end = True). Apply boundary
detection at the end of conditional text, fixing existing
problems of Spanish etc.

Reported by JuanmaSP in GitHub issue #70 and Antonio Bueno in #94.
  • Loading branch information
laszlonemeth committed Nov 3, 2022
1 parent e410849 commit ecb3d68
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions java/src/main/org/numbertext/Soros.java
Expand Up @@ -27,7 +27,7 @@ public class Soros {

private static Pattern func = Pattern.compile(translate("(?:\\|?(?:\\$\\()+)?" + // optional nested calls
"(\\|?\\$\\(([^\\(\\)]*)\\)\\|?)" + // inner call (2 subgroups)
"(?:\\)+\\|?)?", // optional nested calls
"(?:\uE00A?\\)+\\|?)?", // optional nested calls
m2.substring(0, c.length()), c, "\\")); // \$, \(, \), \| -> \uE000..\uE003

public Soros(String source, String lang) {
Expand Down Expand Up @@ -74,7 +74,6 @@ public Soros(String source, String lang) {
// call inner separator: [ ... $1 ... ] -> $(\uE00A ... \uE00A$1\uE00A ... )
s2 = s2.replaceAll("^\\[[$](\\d\\d?|\\([^\\)]+\\))", "\\$(\uE00A\uE00A|\\$$1\uE00A"); // add "|"
s2 = s2.replaceAll("\\[([^$\\[\\\\]*)[$](\\d\\d?|\\([^\\)]+\\))", "\\$(\uE00A$1\uE00A\\$$2\uE00A");
s2 = s2.replaceAll("\uE00A\\]$", "|\uE00A)"); // add "|" in terminating position
s2 = s2.replaceAll("\\]", ")");
s2 = s2.replaceAll("(\\$\\d|\\))\\|\\$", "$1||\\$"); // $()|$() -> $()||$()
s2 = translate(s2, c, m, ""); // \uE000..\uE003-> \, ", ;, #
Expand Down
3 changes: 1 addition & 2 deletions src/Soros.cxx
Expand Up @@ -29,7 +29,7 @@ const std::wstring Soros::pipe = L"\uE003";
const wregex Soros::func ( Soros::translate (
L"(?:\\|?(?:\\$\\()+)?" // optional nested calls
"(\\|?\\$\\(([^\\(\\)]*)\\)\\|?)" // inner call (2 subgroups)
"(?:\\)+\\|?)?", // optional nested calls
"(?:\uE00A?\\)+\\|?)?", // optional nested calls
Soros::m2.substr(0, 4), Soros::c, L"\\")); // \$, \(, \), \| -> \uE000..\uE003

void Soros::replace(std::wstring& s, const std::wstring& search,
Expand Down Expand Up @@ -122,7 +122,6 @@ Soros::Soros(std::wstring program, std::wstring filtered_lang):
L"$$(" SEP SEP L"|$$$1" SEP); // add "|" in terminating position
s2 = regex_replace(s2, wregex(L"\\[([^$\\[\\\\]*)[$](\\d\\d?|\\([^\\)]+\\))"),
L"$$(" SEP L"$1" SEP L"$$$2" SEP);
s2 = regex_replace(s2, wregex(SEP L"\\]$"), L"|" SEP L")"); // add "|" in terminating position
s2 = translate(s2, L"]", L")", L"");
s2 = regex_replace(s2, wregex(L"([$]\\d|\\))\\|[$]"), L"$1||$$"); // $()|$() -> $()||$()
s2 = translate(s2, c, m, L""); // \uE000..\uE003-> \, ", ;, #
Expand Down
3 changes: 1 addition & 2 deletions src/Soros.js
@@ -1,5 +1,5 @@
function Soros(program, lang) {
this.funcpat = /(\|?(\uE008\()+)?(\|?\uE008\(([^\(\)]*)\)\|?)(\)+\|?)?/
this.funcpat = /(\|?(\uE008\()+)?(\|?\uE008\(([^\(\)]*)\)\|?)(\uE00A?\)+\|?)?/
this.meta = "\\\"$()|#;[]"
this.enc = "\uE000\uE001\uE002\uE003\uE004\uE005\uE006\uE007\uE008\uE009"
this.lines = []
Expand Down Expand Up @@ -116,7 +116,6 @@ function Soros(program, lang) {
// call inner separator: [ ... $1 ... ] -> $(\uE00A ... \uE00A$1\uE00A ... )
.replace(/^[[]\$(\d\d?|\([^\)]+\))/g,"$(\uE00A\uE00A|$$$1\uE00A")
.replace(/[[]([^\$[\\]*)\$(\d\d?|\([^\)]+\))/g,"$(\uE00A$1\uE00A$$$2\uE00A")
.replace(/\uE00A]$/, "|\uE00A)") // add "|" in terminating position
.replace(/]/g, ")")
.replace(/(\$\d|\))\|\$/g,"$1||$$") // $(..)|$(..) -> $(..)||$(..)
.replace(/\$/g, "\uE008")
Expand Down
3 changes: 1 addition & 2 deletions src/Soros.py
Expand Up @@ -24,7 +24,7 @@ def _tr(text, chars, chars2, delim):
# pattern to recognize function calls in the replacement string
_func = re.compile(_tr(r"""(?:\|?(?:\$\()+)? # optional nested calls
(\|?\$\(([^\(\)]*)\)\|?) # inner call (2 subgroups)
(?:\)+\|?)?""", # optional nested calls
(?:\uE00A?\)+\|?)?""", # optional nested calls
_m[4:8], _c[:4], "\\"), re.X) # \$, \(, \), \| -> \uE000..\uE003

class _Soros:
Expand Down Expand Up @@ -72,7 +72,6 @@ def __init__(self, prg, lang):
# call inner separator: [ ... $1 ... ] -> $(\uE00A ... \uE00A$1\uE00A ... )
s2 = re.sub(r"[\[]\$(\d\d?|\([^\)]+\))",u"$(\uE00A\uE00A|$\\1\uE00A", s2)
s2 = re.sub(r"[\[]([^\$[\\]*)\$(\d\d?|\([^\)]+\))",u"$(\uE00A\\1\uE00A$\\2\uE00A", s2)
s2 = re.sub(r"\uE00A]$","|\uE00A)", s2) # add "|" in terminating position
s2 = re.sub(r"]",")", s2)
s2 = re.sub(r"(\$\d|\))\|\$", r"\1||$", s2) # $()|$() -> $()||$()
s2 = _tr(s2, _c[:4], _m[:4], "") # \uE000..\uE003-> \, ", ;, #
Expand Down

0 comments on commit ecb3d68

Please sign in to comment.