Skip to content

Commit faced8c

Browse files
authored
Add $Language; guard against missing doc (#1497)
A couple of things were noticed during the release: * `$Language` should have been added with `Alphabet[]` * Guard against crashing when a docstring definition is missing.
1 parent dce5300 commit faced8c

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

mathics/builtin/atomic/strings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,20 @@ class Alphabet(Builtin):
238238
Some languages are aliases. "Russian" is the same letter set as "Cyrillic"
239239
>> Alphabet["Russian"] == Alphabet["Cyrillic"]
240240
= True
241+
242+
See also <url>
243+
:$Language:
244+
/doc/reference-of-built-in-symbols/global-system-information/\\$language/
245+
</url>.
246+
241247
"""
242248

243249
messages = {
244250
"nalph": "The alphabet `` is not known or not available.",
245251
}
246252

247253
rules = {
248-
"Alphabet[]": """Alphabet["English"]""",
254+
"Alphabet[]": """Alphabet[$Language]""",
249255
}
250256

251257
summary_text = "lowercase letters in an alphabet"

mathics/builtin/system.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,58 @@ def eval(self, var, evaluation: Evaluation):
215215
evaluation.message("GetEnvironment", "name", var)
216216

217217

218+
# The current value of $Language
219+
LANGUAGE = "English"
220+
221+
222+
class Language(Predefined):
223+
"""
224+
<url>
225+
:WMA link:
226+
https://reference.wolfram.com/language/ref/\\$Language.html</url>
227+
228+
<dl>
229+
<dt>'\\$Language'
230+
<dd>is a settable global variable for the default language used in Mathics3.
231+
</dl>
232+
233+
See the language in effect used for functions like 'Alphabet[]':
234+
235+
By setting its value, The letters of 'Alphabet[]' are changed:
236+
237+
>> $Language = "German"; Alphabet[]
238+
= ...
239+
240+
#> $Language = "English"
241+
= English
242+
243+
See also <url>
244+
:Alphabet:
245+
/doc/reference-of-built-in-symbols/atomic-elements-of-expressions/string-manipulation/alphabet/
246+
</url>.
247+
"""
248+
249+
name = "$Language"
250+
messages = {
251+
"notstr": "`1` is not a string. Only strings can be set as the value of $Language.",
252+
}
253+
254+
summary_text = "settable global variable giving the default language"
255+
value = f'"{LANGUAGE}"'
256+
# Rules has to come after "value"
257+
rules = {
258+
"$Language": value,
259+
}
260+
261+
def eval_set(self, value, evaluation: Evaluation):
262+
"""Set[$Language, value_]"""
263+
if isinstance(value, String):
264+
evaluation.definitions.set_ownvalue("$Language", value)
265+
else:
266+
evaluation.message("$Language", "notstr", value)
267+
return value
268+
269+
218270
class Machine(Predefined):
219271
"""
220272
<url>:WMA link:https://reference.wolfram.com/language/ref/\\$Machine.html</url>

mathics/doc/doc_entries.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,11 @@ def text(self) -> str:
643643
# used for introspection
644644
# TODO parse XML and pretty print
645645
# HACK
646+
647+
# The following is probably an indication of improper docstring
648+
# tagging. But don't crash here.
646649
if len(self.items) == 0:
650+
print(f"Bad doc formatting for {self.title}")
647651
return "No documentation"
648652
item = str(self.items[0])
649653
item = "\n".join(line.strip() for line in item.split("\n"))
@@ -653,7 +657,7 @@ def text(self) -> str:
653657
item = item.replace("</dt>", "")
654658
item = item.replace("<dd>", " ")
655659
item = item.replace("</dd>", "")
656-
item = item.replace("\\$", "_DOLARSIGN_")
660+
item = item.replace("\\$", "_DOLLARSIGN_")
657661
item = (
658662
item.replace("\\'", "_SINGLEQUOTE_")
659663
.replace("'", "")
@@ -664,7 +668,7 @@ def text(self) -> str:
664668

665669
item = re.sub(r"\$([0-9a-zA-Z]*)\_\{([0-9a-zA-Z]*)\}\$", r"\1\2", item)
666670
item = re.sub(r"\$([0-9a-zA-Z]*)\_([0-9a-zA-Z]*)\$", r"\1\2", item)
667-
item = item.replace("_DOLARSIGN_", "$")
671+
item = item.replace("_DOLLARSIGN_", "$")
668672
return item
669673

670674

0 commit comments

Comments
 (0)