onlinejudge_template.analyzer.typing module¶
the module to infer types of variables in format trees
この module はフォーマット木の中に自由に出現する変数の型を推論します。 サンプル文字列とのマッチ結果を解析することで実装されています。
たとえば
sequence([
item("N"),
newline(),
loop(counter="i", size="N", sequence([
item("A", indices="i"),
newline(),
)),
])
のようなフォーマット木 (FormatNode
) と
3
ABA
AAABA
BAAB
というサンプル文字列が与えられれば
{
"N": int,
"A": str,
}
に相当する結果を返します。
-
onlinejudge_template.analyzer.typing.
get_var_type
(value: Union[int, float, str]) → onlinejudge_template.types.VarType[source]¶
-
onlinejudge_template.analyzer.typing.
get_var_types_from_match_result
(values: Dict[NewType.<locals>.new_type, Dict[Tuple[int, ...], Union[int, float, str]]], *, variables: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl]) → Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType][source]¶ Raises: TypingError –
-
onlinejudge_template.analyzer.typing.
infer_types_from_instances
(node: onlinejudge_template.types.FormatNode, *, variables: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl], instances: List[str]) → Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType][source]¶ Raises:
-
onlinejudge_template.analyzer.typing.
unify_types
(t1: onlinejudge_template.types.VarType, t2: onlinejudge_template.types.VarType) → onlinejudge_template.types.VarType[source]¶
-
onlinejudge_template.analyzer.typing.
unify_var_types
(t1: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType], t2: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType]) → Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType][source]¶
-
onlinejudge_template.analyzer.typing.
update_variables_with_types
(*, variables: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl], types: Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarType]) → Dict[NewType.<locals>.new_type, onlinejudge_template.types.VarDecl][source]¶ Raises: TypingError –