Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 3
0
def _handle_anon(
    inter: InterpretContext,
    anon_body: d_Body,
    orig_loc: CodeLocation,
    lang: Optional[d_Lang] = None,
) -> Optional[d_Body]:
    if anon_body.name:
        # traditional statement, stop here
        if lang and isinstance(anon_body, d_Lang):
            # a language is being redeclared, must call set_value to
            # activate priority comparison stuff
            lang.set_value(anon_body)
        else:
            inter.body.attrs[d_Variable(anon_body.name)] = anon_body
        inter.named_statement = True
        return None
    else:
        # anonymous expression, need to dispatch it
        inter.anon_tok = Token(anon_body.grammar, orig_loc, thing=anon_body)
        return _expression_dispatch(inter)  # type: ignore