Beispiel #1
0
    def opcodes(self, debug=False):
        ops = Opcodes()

        #XXX if token is ignored (and no callbacks) jump to start
        # if self.token in ('WS','WS_INLINE','NEWLINE','CR','LF'):
        #     # print('WS HACK! -- REMOVE ME!')
        #     if debug:
        #         ops << Debug('FSM> Ignoring: <{}> (ofs: {}, cursor: {})', self.token, '$ofs', '$YYCURSOR').opcodes()

        #     ops << LOAD_FAST('YYCURSOR')
        #     ops << STORE_FAST('ofs')
        #     ops << Goto('$START').opcodes(debug)
        #     return ops

        if debug:
            ops << Debug('FSM> Produce: <{}> (ofs: {}, cursor: {})',
                         self.token, '$ofs', '$YYCURSOR').opcodes()

        # > return (ofs, YYCURSOR, self.token)
        ops << LOAD_FAST('ofs')
        ops << LOAD_FAST('YYCURSOR')
        ops << LOAD_CONST(self.token)
        ops << BUILD_TUPLE(3)
        ops << RETURN_VALUE()
        return ops
Beispiel #2
0
    def opcodes(self, debug=False):
        ops = Opcodes()
        ops << LOAD_FAST(self.var)
        ops << STORE_FAST('YYCURSOR')

        if debug:
            ops << Debug('FSM> Restore (cursor: {})', '$YYCURSOR').opcodes()

        return ops
Beispiel #3
0
    def opcodes(self, debug=False):
        ops = Opcodes()
        ops << LOAD_FAST('YYCURSOR')
        ops << LOAD_CONST(1)
        ops << INPLACE_ADD()  # > ofs + 1
        ops << STORE_FAST('YYCURSOR')  # > ofs = ofs + 1

        if debug:
            ops << Debug('FSM> Advance (cursor: {})', '$YYCURSOR').opcodes()

        return ops
Beispiel #4
0
    def opcodes(self, debug=False):
        ops = Opcodes()

        ops << LOAD_CONST(self.mark)
        ops << STORE_FAST('yyaccept')

        if debug:
            ops << Debug('FSM> Mark: {} (cursor: {})', '$yyaccept',
                         '$YYCURSOR').opcodes()

        return ops
Beispiel #5
0
    def opcodes(self, debug=False):
        ops = Opcodes()
        ops << LOAD_FAST('YYCURSOR')
        ops << LOAD_CONST(1)
        ops << INPLACE_SUBTRACT()
        ops << STORE_FAST('YYCURSOR')

        if debug:
            ops << Debug('FSM> Retract (cursor: {})', '$YYCURSOR').opcodes()

        return ops
Beispiel #6
0
    def opcodes(self, debug=False):
        ops = Opcodes()
        ops << LOAD_FAST('stream')
        ops << LOAD_FAST('YYCURSOR')
        ops << BINARY_SUBSCR()  # > stream[ofs]
        ops << STORE_FAST('yych')  # > yych = stream[ofs]

        if debug:
            ops << Debug('FSM> Consume: {} (cursor: {})', '$yych',
                         '$YYCURSOR').opcodes()

        return ops