示例#1
0
def _dotable(inter: InterpretContext) -> Optional[d_Thing]:
    if inter.next_tok.grammar == d_Grammar.DOT:
        # ... someBody.Ele ...
        dot = _dot(inter)
        inter.next_tok = dot
        inter.anon_tok = None
        inter.call_tok = None
        return _expression_dispatch(inter)
    else:
        return _equalable(inter)
示例#2
0
def _terminal(inter: InterpretContext) -> d_Thing:
    # someValue;
    # someListArg,
    # someListArg]
    # someFuncArg)
    # someTriangleVar! (the exclamation point is inserted by the preprocessor)
    if inter.next_tok.grammar not in [
            d_Grammar.SEMI,
            d_Grammar.COMMA,
            d_Grammar.BRACKET_RIGHT,
            d_Grammar.PAREN_RIGHT,
            d_Grammar.POINT,
    ]:
        if inter.declaring_func or inter.in_json:
            pass
        elif inter.comma_depth == 0:
            _missing_terminal(inter, "Expected ';'")
        else:
            _missing_terminal(inter, "Expected ']'")

    if not inter.equaling:
        # this.A.Make();
        # someClass.doThing();
        # We dotted something, and need to clear that out.
        # But not if we're equaling:
        # this.A.value = someClass.value;
        # _terminal will actually be called again, and these will be cleared then.
        inter.dotted_body = None  # type: ignore
        inter.dotted_inst = None  # type: ignore

    if inter.anon_tok:
        ret = inter.anon_tok.thing
        inter.anon_tok = None
        return ret
    elif inter.call_tok:
        ret = inter.call_tok.thing
        inter.call_tok = None
        return ret
    else:
        inter.terminal_loc = copy.deepcopy(inter.curr_tok.loc)
        # This return is how _equals gets it's value.
        return inter.curr_tok.thing
示例#3
0
def _paren_left(inter: InterpretContext) -> Optional[d_Thing]:
    func = (inter.anon_tok or inter.call_tok or inter.curr_tok).thing
    if isinstance(func, d_Class):
        # This means we must be instantiating, and need the Make func
        # Number num = Number('3');
        func = _make(inter)
    elif not isinstance(func, d_Func):
        raise d_CriticalError(f"Expected function, got {func.public_type}")

    func.new_call()  # handles recursive attribute stack

    stored_inst = None
    if inter.dotted_inst and not inter.equaling:
        # We are activating a function of this instance, so the func needs 'this'
        # Subject to change when static functions are implemented
        # num.inc();
        func.add_attr(
            Declarable(inter.dotted_inst.parent, THIS),
            inter.dotted_inst,
            use_ref=True,
        )
        stored_inst = inter.dotted_inst
    inter.dotted_inst = None  # type: ignore

    _get_func_args(inter, func)

    if not func.code and func.lang is not b_Ditlang:
        preprocess(func)

    inter.call_tok = _run_func(inter, func)

    func.end_call()

    if stored_inst:
        stored_inst.pop_func_sep()

    if inter.call_tok.grammar == d_Grammar.NULL:
        return _terminal(inter)
    else:
        return _parenable(inter)