def make_none(p: YaccProduction, token: int) -> Literal: assert namespace none = Literal(NoneValue()) none.location = Location(file, p.lineno(token)) none.namespace = namespace none.lexpos = p.lexpos(token) return none
def test_slots_rt(): ns = Namespace("root", None) rs = Resolver(ns) e = Entity("xx", ns) qs = QueueScheduler(None, [], [], None, set()) r = RelationAttribute(e, None, "xx", Location("", 1)) i = Instance(e, rs, qs) assert_slotted(ResultVariable()) assert_slotted(AttributeVariable(None, None)) assert_slotted(Promise(None, None)) assert_slotted(ListVariable(r, i, qs)) assert_slotted(OptionVariable(r, i, qs)) assert_slotted(qs) assert_slotted(DelegateQueueScheduler(qs, None)) assert_slotted(Waiter(qs)) assert_slotted( ExecutionUnit(qs, r, ResultVariable(), {}, Literal(""), None)) assert_slotted(HangUnit(qs, r, {}, None, Resumer())) assert_slotted(RawUnit(qs, r, {}, Resumer())) assert_slotted(FunctionUnit(qs, rs, ResultVariable(), {}, None)) assert_slotted(i)
def p_relation(p): "relation : class_ref ID multi REL multi class_ref ID" if not (p[4] == '--'): LOGGER.warning( "DEPRECATION: use of %s in relation definition is deprecated, use -- (in %s)" % (p[4], Location(file, p.lineno(4)))) p[0] = DefineRelation((p[1], p[2], p[3]), (p[6], p[7], p[5])) attach_lnr(p, 2)
def p_relation_deprecated_comment(p: YaccProduction) -> None: "relation : class_ref ID multi REL multi class_ref ID MLS" if not (p[4] == "--"): LOGGER.warning( "DEPRECATION: use of %s in relation definition is deprecated, use -- (in %s)" % (p[4], Location(file, p.lineno(4)))) rel = DefineRelation((p[1], p[2], p[3]), (p[6], p[7], p[5])) rel.comment = str(p[8]) p[0] = rel attach_lnr(p, 2) deprecated_relation_warning(p)
def p_string(p): " constant : STRING " value = p[1] match_obj = format_regex_compiled.findall(value) if len(match_obj) > 0: p[0] = create_string_format(value, match_obj, Location(file, p.lineno(1))) else: p[0] = Literal(value) attach_lnr(p)
def test_attribute_validate(multi: bool, nullable: bool) -> None: entity: Entity = Entity("DummyEntity", Namespace("dummy_namespace")) attribute: Attribute = Attribute(entity, Integer(), "my_attribute", Location("dummy.cf", 1), multi, nullable) def validate(value: object, success: bool) -> None: if success: attribute.validate(value) else: with pytest.raises(RuntimeException): attribute.validate(value) validate(42, not multi) validate(NoneValue(), nullable) validate([0, 1, 2], multi) validate([0, 1, NoneValue()], False)
def __init__(self, namespace: Namespace) -> None: self.ns = namespace self.namespace = namespace self._context = -1 self._return = None self.arguments: List[Tuple] if hasattr(self.__class__, "__function__"): self.arguments = self._load_signature(self.__class__.__function__) else: self.arguments = [] self.new_statement = None filename: Optional[str] = inspect.getsourcefile( self.__class__.__function__) assert filename is not None line: int = inspect.getsourcelines(self.__class__.__function__)[1] + 1 self.location = Location(filename, line)
def p_constructor(p: YaccProduction) -> None: "constructor : class_ref '(' param_list ')'" assert namespace p[0] = Constructor(p[1], p[3][0], p[3][1], Location(file, p.lineno(2)), namespace)
def test_slots_ast(): assert_slotted(Location("", 0)) assert_slotted(Range("", 0, 0, 0, 0))
def attach_lnr_for_parser(p, token=1): v = p[0] p[0] = LocatableString(v, Location(file, p.lineno(token)), p.lexpos(token), namespace)
def attach_lnr(p, token=1): v = p[0] v.location = Location(file, p.lineno(token)) v.namespace = namespace v.lexpos = p.lexpos(token)
def p_constructor_empty(p): " constructor : class_ref '(' ')' " p[0] = Constructor(p[1], [], Location(file, p.lineno(2)), namespace)
def p_constructor(p): " constructor : class_ref '(' param_list ')' " p[0] = Constructor(p[1], p[3], Location(file, p.lineno(2)), namespace)
def p_attribute_type_multi_opt(p): "attr_type_multi : ns_ref '[' ']' '?'" p[0] = (str(p[1]), True, Location(file, p.lineno(1)))
def p_attribute_type_multi(p): "attr_type_multi : ns_ref '[' ']'" p[0] = (str(p[1]), False, Location(file, p.lineno(1)))
def p_function_call(p: YaccProduction) -> None: "function_call : ns_ref '(' function_param_list ')'" assert namespace (args, kwargs, wrapped_kwargs) = p[3] p[0] = FunctionCall(p[1], args, kwargs, wrapped_kwargs, Location(file, p.lineno(2)), namespace)
def attach_lnr(p: YaccProduction, token: int = 1) -> None: v = p[0] v.location = Location(file, p.lineno(token)) v.namespace = namespace v.lexpos = p.lexpos(token)
def p_constant_string(p: YaccProduction) -> None: " constant : STRING " p[0] = get_string_ast_node(p[1], Location(file, p.lineno(1))) attach_lnr(p)