Example #1
0
def test_slots_rt():
    ns = Namespace("root", None)
    rs = Resolver(ns)
    e = Entity("xx", ns)
    qs = QueueScheduler(None, [], [], {}, set())
    r = RelationAttribute(e, None, "xx", Location("", 1))
    i = Instance(e, rs, qs)
    sa = SetAttribute(Reference("a"), "a", Literal("a"))

    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)
    assert_slotted(GradualSetAttributeHelper(sa, i, "A", ResultVariable()))
    assert_slotted(
        SetAttributeHelper(qs, rs, ResultVariable(), {}, Literal("A"), sa, i,
                           "A"))
Example #2
0
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
Example #3
0
def p_constant(p):
    """ constant : INT
    | FLOAT
    | mls
    """
    p[0] = Literal(p[1])
    attach_lnr(p)
Example #4
0
def get_string_ast_node(string_ast: LocatableString,
                        mls: bool) -> Union[Literal, StringFormat]:
    matches: List[re.Match[str]] = list(
        format_regex_compiled.finditer(str(string_ast)))
    if len(matches) == 0:
        return Literal(str(string_ast))

    start_lnr = string_ast.location.lnr
    start_char_pos = string_ast.location.start_char
    whole_string = str(string_ast)
    mls_offset: int = 3 if mls else 1  # len(""")  or len(') or len(")

    def char_count_to_lnr_char(position: int) -> Tuple[int, int]:
        # convert in-string position to lnr/charcount
        before = whole_string[0:position]
        lines = before.count("\n")
        if lines == 0:
            return start_lnr, start_char_pos + position + mls_offset
        else:
            return start_lnr + lines, position - before.rindex("\n")

    locatable_matches: List[Tuple[str, LocatableString]] = []
    for match in matches:
        start_line, start_char = char_count_to_lnr_char(match.start(2))
        end_line, end_char = char_count_to_lnr_char(match.end(2))
        range: Range = Range(string_ast.location.file, start_line, start_char,
                             end_line, end_char)
        locatable_string = LocatableString(match[2], range, string_ast.lexpos,
                                           string_ast.namespace)
        locatable_matches.append((match[1], locatable_string))
    return create_string_format(string_ast, locatable_matches)
Example #5
0
def p_attr_list_null(p):
    "attr : attr_type_multi ID '=' NULL"
    (attr, nullable, _) = p[1]
    p[0] = DefineAttribute(attr,
                           p[2],
                           Literal(NoneValue()),
                           True,
                           nullable=nullable)
    attach_lnr(p, 3)
Example #6
0
def p_implement(p: YaccProduction) -> None:
    """implement_def : IMPLEMENT class_ref USING implement_ns_list empty
    | IMPLEMENT class_ref USING implement_ns_list MLS"""
    (inherit, implementations) = p[4]
    p[0] = DefineImplement(p[2],
                           implementations,
                           Literal(True),
                           inherit=inherit,
                           comment=p[5])
    attach_lnr(p)
Example #7
0
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)
Example #8
0
    def set_expression(self, expression: ExpressionStatement) -> None:
        """
        Set the expression that constrains the basetype. This expression
        should reference the value that will be assign to a variable of this
        type. This variable has the same name as the type.
        """
        contains_var = False

        if hasattr(expression, "arguments"):
            # some sort of function call
            expression = Equals(expression, Literal(True))

        for var in expression.requires():
            if var == self.name or var == "self":
                contains_var = True

        if not contains_var:
            raise TypingException(self, "typedef expressions should reference the self variable")

        self.__expression = expression
def get_string_ast_node(string: LocatableString,
                        location: Location) -> Union[Literal, StringFormat]:
    match_obj = format_regex_compiled.findall(str(string))
    if len(match_obj) == 0:
        return Literal(str(string))
    return create_string_format(string, match_obj, location)
Example #10
0
def p_constant_rstring(p: YaccProduction) -> None:
    "constant : RSTRING"
    p[0] = Literal(str(p[1]))
    attach_from_string(p)
Example #11
0
def p_constant_false(p: YaccProduction) -> None:
    """constant : FALSE"""
    p[0] = Literal(False)
    attach_lnr(p)
Example #12
0
def p_constant_true(p: YaccProduction) -> None:
    """constant : TRUE"""
    p[0] = Literal(True)
    attach_lnr(p)
Example #13
0
def p_constant(p: YaccProduction) -> None:
    """constant : INT
    | FLOAT
    """
    p[0] = Literal(p[1])
    attach_lnr(p)
Example #14
0
def p_attr_list_dict_null(p):
    "attr : DICT '?'  ID '=' NULL"
    p[0] = DefineAttribute("dict", p[3], Literal(NoneValue()), nullable=True)
    attach_lnr(p, 1)
Example #15
0
def p_implement_comment(p):
    "implement_def : IMPLEMENT class_ref USING ns_list mls"
    p[0] = DefineImplement(p[2], p[4], Literal(True), comment=p[5])
    attach_lnr(p)
Example #16
0
 def __init__(self, op1, op2):
     regex = re.compile(op2)
     BinaryOperator.__init__(self, "regex", op1, Literal(regex))
Example #17
0
 def __init__(self, op1: ExpressionStatement, op2: str):
     self.regex = re.compile(op2)
     super().__init__("regex", op1, Literal(self.regex))
Example #18
0
def p_condition_term_1(p):
    """condition : TRUE
                | FALSE"""
    p[0] = Literal(p[1])
    attach_lnr(p)
Example #19
0
def p_constant_f(p):
    """ constant : FALSE
    """
    p[0] = Literal(False)
    attach_lnr(p)
Example #20
0
def p_constant_t(p):
    """ constant : TRUE
    """
    p[0] = Literal(True)
    attach_lnr(p)
Example #21
0
def p_constant_none(p):
    """ constant : NULL
    """
    p[0] = Literal(NoneValue())
    attach_lnr(p)