Ejemplo n.º 1
0
def r(ctx: Context, token: TokenInfo):
    directive = token.lxfmt_directive()
    if directive == "off" and ctx.last_state != State.DISABLED:
        ctx.push_state(State.DISABLED)

    elif directive == "on" and ctx.last_state == State.DISABLED:
        ctx.pop_state()
Ejemplo n.º 2
0
def r(ctx: Context, token: TokenInfo):
    if not ctx.last_op[0].annotation in (A.CLS_BODY_LSQB, A.BODY_LSQB):
        return

    ctx.cache = [token]
    ctx.push_state(State.EXPECT_AUGASSIGN_DASH)
    return actions.StartBuffer()
Ejemplo n.º 3
0
def r(ctx: Context, token: TokenInfo):
    t, state = ctx.pop_op()
    if state not in (State.EXPECT_LBDX_LSQB, State.IN_LBDX_CALL) or not tk.ISMATCHED(t, token):
        ctx.error()

    if t.annotation == A.DECL_LPAR:
        ctx.pop_state()
        ctx.pop_state()
        token.annotation = A.DECL_RPAR
Ejemplo n.º 4
0
def r(ctx: Context, token: TokenInfo):
    last_state = ctx.pop_state()
    ctx.cache.append(token)

    new_state = {
        State.EXPECT_SUBCLS_NAME: State.EXPECT_CLS_HEAD_OR_BODY_LSQB,
        State.MUST_SUBCLS_NAME_WITH_HEAD: State.EXPECT_CLS_HEAD_LSQB,
        State.MUST_SUBCLS_NAME_WITH_BODY: State.EXPECT_CLS_BODY_LSQB,
    }[last_state]

    ctx.push_state(new_state)
Ejemplo n.º 5
0
def r(ctx: Context, token: TokenInfo):

    ctx.pop_state()
    ctx.push_state(State.IN_LBDX_BODY_LIST)
    token.annotation = A.BODY_LSQB
    ctx.push_op(token)
    ctx.push_ret(token)

    sentinel = TokenInfo.new_sentinel_after(token, A.STMT_START)
    ctx.push_ret(sentinel)

    return actions.Default(dont_store=True)
Ejemplo n.º 6
0
def r(ctx: Context, token: TokenInfo):
    last_state = ctx.pop_state()

    new_state = {
        State.EXPECT_SUBCLS_DOT: State.EXPECT_SUBCLS_NAME,
        State.MUST_SUBCLS_DOT_WITH_HEAD: State.MUST_SUBCLS_NAME_WITH_HEAD,
        State.MUST_SUBCLS_DOT_WITH_BODY: State.MUST_SUBCLS_NAME_WITH_BODY,
    }[last_state]

    ctx.push_state(new_state)
    ctx.cache = [token]

    return actions.StartBuffer()
Ejemplo n.º 7
0
def _annotate_clause_declarer(ctx: Context):
    if ctx.cache is None:
        return actions.Default()
    if not isinstance(ctx.cache, list):
        ctx.error()
    length = len(ctx.cache)
    if length == 1:
        ctx.cache[0].annotation = A.CLS_DECL
    elif length == 2:
        ctx.cache[0].annotation = A.CLS_DOT
        ctx.cache[1].annotation = A.CLS_DECL
    else:
        ctx.error()
Ejemplo n.º 8
0
def r(ctx: Context, token: TokenInfo):
    if ctx.pop_op()[0].annotation == A.CLS_BODY_LSQB:
        ctx.pop_state()
        ctx.push_state(State.EXPECT_SUBCLS_DOT)

        sentinel = TokenInfo.new_sentinel_before(token, A.STMT_END)
        ctx.push_ret(sentinel)
        token.annotation = A.CLS_BODY_RSQB
        ctx.push_ret(token)
        return actions.Default(dont_store=True)
Ejemplo n.º 9
0
def r(ctx: Context, token: TokenInfo):
    token.annotation = A.CLS_HEAD_LSQB
    ctx.push_op(token)
    ctx.pop_state()
    ctx.push_state(State.IN_LBDX_CLS_HEAD)

    _annotate_clause_declarer(ctx)
    ctx.cache = None
    if ctx.is_buffering():
        return actions.StopBuffer()
Ejemplo n.º 10
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    sentinel = TokenInfo.new_sentinel_before(token, A.STMT_END)
    ctx.push_ret(sentinel)

    token.annotation = A.STMT_COMMA
    ctx.push_ret(token)

    sentinel = TokenInfo.new_sentinel_after(token, A.STMT_START)
    ctx.push_ret(sentinel)

    if ctx.is_buffering():
        return actions.StopBuffer(dont_store=True)

    return actions.Default(dont_store=True)
Ejemplo n.º 11
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()

    ctx.cache.annotation = A.DECL
    ctx.push_state(State.IN_LBDX_CALL)
    token.annotation = A.DECL_LPAR
    ctx.push_op(token)
    return actions.StopBuffer()
Ejemplo n.º 12
0
def r(ctx: Context, token: TokenInfo):
    sentinel = TokenInfo.new_sentinel_before(token, A.STMT_END)
    ctx.push_ret(sentinel)

    token.annotation = A.STMT_COMMA
    ctx.push_ret(token)

    sentinel = TokenInfo.new_sentinel_after(token, A.STMT_START)
    ctx.push_ret(sentinel)

    return actions.Default(dont_store=True)
Ejemplo n.º 13
0
def r(ctx: Context, token: TokenInfo):
    if ctx.last_op[0].annotation not in (A.BODY_LSQB, A.CLS_BODY_LSQB):
        return

    sentinel = TokenInfo.new_sentinel_before(token, A.STMT_END)
    ctx.push_ret(sentinel)

    token.annotation = A.STMT_COMMA
    ctx.push_ret(token)

    sentinel = TokenInfo.new_sentinel_after(token, A.STMT_START)
    ctx.push_ret(sentinel)

    return actions.Default(dont_store=True)
Ejemplo n.º 14
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.push_state(State.EXPECT_LBDX_NAME)
Ejemplo n.º 15
0
def r(ctx: Context, token: TokenInfo):
    ctx.push_state(State.EXPECT_LBDX_LPAR)

    ctx.cache = token
    return actions.StartBuffer()
Ejemplo n.º 16
0
def r(ctx: Context, token: TokenInfo):
    ltoken, state = ctx.pop_op()
    if not tk.ISMATCHED(ltoken, token) or state != ctx.last_state:
        ctx.error()
Ejemplo n.º 17
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.cache[0].annotation = A.AUGASSIGN_START
    token.annotation = A.AUGASSIGN_END
    return actions.StopBuffer()
Ejemplo n.º 18
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.push_state(State.EXPECT_AUGASSIGN_ASSIGN)
    return
Ejemplo n.º 19
0
def r(ctx: Context, token: TokenInfo):
    ctx.push_op(token)
Ejemplo n.º 20
0
def r(ctx: Context, token: TokenInfo):
    if ctx.is_buffering():
        return actions.StopBuffer(dont_consume=True)

    ctx.pop_state()
    ctx.push_state(State.IN_LBDX_CLS_BODY)
    token.annotation = A.CLS_BODY_LSQB
    ctx.push_op(token)

    _annotate_clause_declarer(ctx)
    ctx.cache = None

    ctx.push_ret(token)
    sentinel = TokenInfo.new_sentinel_after(token, A.STMT_START)
    ctx.push_ret(sentinel)

    return actions.Default(dont_store=True)
Ejemplo n.º 21
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    return actions.StopBuffer()
Ejemplo n.º 22
0
def r(ctx: Context, token: TokenInfo):
    ctx.push_op(token)
    ctx.pop_state()
    ctx.push_state(State.EXPECT_CLS_HEAD_OR_BODY_RSQB)
Ejemplo n.º 23
0
def r(ctx: Context, token: TokenInfo):
    if ctx.pop_op()[1] == State.EXPECT_CLS_HEAD_LSQB:
        ctx.pop_state()
        ctx.push_state(State.EXPECT_CLS_BODY_LSQB)
        token.annotation = A.CLS_HEAD_RSQB
Ejemplo n.º 24
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.cache = None
    return actions.StopBuffer(dont_consume=True)
Ejemplo n.º 25
0
def r(ctx: Context, token: TokenInfo):
    ctx.push_state(State.EXPECT_CLS_BODY_LSQB)
    ctx.cache = [token]
    return actions.StartBuffer()
Ejemplo n.º 26
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.push_state(State.MUST_LBDX_LPAR)
Ejemplo n.º 27
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    if ctx.is_buffering():
        return actions.StopBuffer(dont_consume=True)
    return actions.Default(dont_consume=True)
Ejemplo n.º 28
0
def r(ctx: Context, token: TokenInfo):
    if ctx.pop_op()[1] == State.EXPECT_CLS_HEAD_OR_BODY_LSQB:
        ctx.pop_state()
        ctx.push_state(State.EXPECT_CLS_MAYBE_BODY_LSQB)
Ejemplo n.º 29
0
    def _init(self):
        assert isinstance(self.tokenseq, BTStream)

        self.context = Context()
        self.context.is_buffering = lambda: self.tokenseq.last_is_buffering()
Ejemplo n.º 30
0
def r(ctx: Context, token: TokenInfo):
    ctx.pop_state()
    ctx.cache.append(token)
    ctx.push_state(State.EXPECT_CLS_HEAD_LSQB)