本文整理汇总了Python中mathics.core.expression.Expression.get_name方法的典型用法代码示例。如果您正苦于以下问题:Python Expression.get_name方法的具体用法?Python Expression.get_name怎么用?Python Expression.get_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathics.core.expression.Expression
的用法示例。
在下文中一共展示了Expression.get_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_msg_list
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import get_name [as 别名]
def get_msg_list(expr):
if expr.has_form('MessageName', 2):
expr = Expression('List', expr)
if expr.get_name() == 'All':
all = True
messages = []
elif expr.get_name() == 'None':
all = False
messages = []
elif expr.has_form('List', None):
all = False
messages = []
for item in expr.leaves:
if item.has_form('MessageName', 2):
symbol = item.leaves[0].get_name()
tag = item.leaves[1].get_string_value()
if symbol and tag:
messages.append((symbol, tag))
else:
raise ValueError
else:
raise ValueError
else:
raise ValueError
return all, messages
示例2: assign_elementary
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import get_name [as 别名]
def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
name = lhs.get_head_name()
if name in ('OwnValues', 'DownValues', 'SubValues', 'UpValues', 'NValues', 'Options',
'DefaultValues', 'Attributes', 'Messages'):
if len(lhs.leaves) != 1:
evaluation.message_args(name, len(lhs.leaves), 1)
return False
tag = lhs.leaves[0].get_name()
if not tag:
evaluation.message(name, 'sym', lhs.leaves[0], 1)
return False
if tags is not None and tags != [tag]:
evaluation.message(name, 'tag', name, tag)
return False
if name != 'Attributes' and 'Protected' in evaluation.definitions.get_attributes(tag):
evaluation.message(name, 'wrsym', tag)
return False
if name == 'Options':
option_values = rhs.get_option_values(evaluation)
if option_values is None:
evaluation.message(name, 'options', rhs)
return False
evaluation.definitions.set_options(tag, option_values)
elif name == 'Attributes':
attributes = get_symbol_list(rhs, lambda item: evaluation.message(name, 'sym', item, 1))
if attributes is None:
return False
if 'Locked' in evaluation.definitions.get_attributes(tag):
evaluation.message(name, 'locked', tag)
return False
evaluation.definitions.set_attributes(tag, attributes)
else:
rules = rhs.get_rules_list()
if rules is None:
evaluation.message(name, 'vrule', lhs, rhs)
return False
evaluation.definitions.set_values(tag, name, rules)
return True
form = ''
nprec = None
default = False
message = False
allow_custom_tag = False
focus = lhs
if name == 'N':
if len(lhs.leaves) not in (1, 2):
evaluation.message_args('N', len(lhs.leaves), 1, 2)
return False
if len(lhs.leaves) == 1:
nprec = Symbol('MachinePrecision')
else:
nprec = lhs.leaves[1]
focus = lhs.leaves[0]
lhs = Expression('N', focus, nprec)
elif name == 'MessageName':
if len(lhs.leaves) != 2:
evaluation.message_args('MessageName', len(lhs.leaves), 2)
return False
focus = lhs.leaves[0]
message = True
elif name == 'Default':
if len(lhs.leaves) not in (1, 2, 3):
evaluation.message_args('Default', len(lhs.leaves), 1, 2, 3)
return False
focus = lhs.leaves[0]
default = True
elif name == 'Format':
if len(lhs.leaves) not in (1, 2):
evaluation.message_args('Format', len(lhs.leaves), 1, 2)
return False
if len(lhs.leaves) == 2:
form = lhs.leaves[1].get_name()
if not form:
evaluation.message('Format', 'fttp', lhs.leaves[1])
return False
else:
form = ('StandardForm', 'TraditionalForm', 'OutputForm',
'TeXForm', 'MathMLForm',
)
lhs = focus = lhs.leaves[0]
else:
allow_custom_tag = True
focus = focus.evaluate_leaves(evaluation)
if tags is None and not upset:
name = focus.get_lookup_name()
if not name:
evaluation.message(self.get_name(), 'setraw', focus)
return False
tags = [name]
elif upset:
if allow_custom_tag:
tags = []
#.........这里部分代码省略.........
示例3: assign_elementary
# 需要导入模块: from mathics.core.expression import Expression [as 别名]
# 或者: from mathics.core.expression.Expression import get_name [as 别名]
def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
name = lhs.get_head_name()
if name in (
"OwnValues",
"DownValues",
"SubValues",
"UpValues",
"NValues",
"Options",
"DefaultValues",
"Attributes",
"Messages",
):
if len(lhs.leaves) != 1:
evaluation.message_args(name, len(lhs.leaves), 1)
return False
tag = lhs.leaves[0].get_name()
if not tag:
evaluation.message(name, "sym", lhs.leaves[0], 1)
return False
if tags is not None and tags != [tag]:
evaluation.message(name, "tag", name, tag)
return False
if name != "Attributes" and "Protected" in evaluation.definitions.get_attributes(tag): # noqa
evaluation.message(name, "wrsym", tag)
return False
if name == "Options":
option_values = rhs.get_option_values(evaluation)
if option_values is None:
evaluation.message(name, "options", rhs)
return False
evaluation.definitions.set_options(tag, option_values)
elif name == "Attributes":
attributes = get_symbol_list(rhs, lambda item: evaluation.message(name, "sym", item, 1))
if attributes is None:
return False
if "Locked" in evaluation.definitions.get_attributes(tag):
evaluation.message(name, "locked", tag)
return False
evaluation.definitions.set_attributes(tag, attributes)
else:
rules = rhs.get_rules_list()
if rules is None:
evaluation.message(name, "vrule", lhs, rhs)
return False
evaluation.definitions.set_values(tag, name, rules)
return True
form = ""
nprec = None
default = False
message = False
allow_custom_tag = False
focus = lhs
if name == "N":
if len(lhs.leaves) not in (1, 2):
evaluation.message_args("N", len(lhs.leaves), 1, 2)
return False
if len(lhs.leaves) == 1:
nprec = Symbol("MachinePrecision")
else:
nprec = lhs.leaves[1]
focus = lhs.leaves[0]
lhs = Expression("N", focus, nprec)
elif name == "MessageName":
if len(lhs.leaves) != 2:
evaluation.message_args("MessageName", len(lhs.leaves), 2)
return False
focus = lhs.leaves[0]
message = True
elif name == "Default":
if len(lhs.leaves) not in (1, 2, 3):
evaluation.message_args("Default", len(lhs.leaves), 1, 2, 3)
return False
focus = lhs.leaves[0]
default = True
elif name == "Format":
if len(lhs.leaves) not in (1, 2):
evaluation.message_args("Format", len(lhs.leaves), 1, 2)
return False
if len(lhs.leaves) == 2:
form = lhs.leaves[1].get_name()
if not form:
evaluation.message("Format", "fttp", lhs.leaves[1])
return False
else:
form = ("StandardForm", "TraditionalForm", "OutputForm", "TeXForm", "MathMLForm")
lhs = focus = lhs.leaves[0]
else:
allow_custom_tag = True
focus = focus.evaluate_leaves(evaluation)
if tags is None and not upset:
name = focus.get_lookup_name()
#.........这里部分代码省略.........