예제 #1
0
    def context(self, tok=None):
        lex = self.lexer
        name = lex.filename if lex.filename else '<string>'

        if tok is None:
            position = pctx.SourcePoint(
                line=lex.lineno, column=lex.column, pointer=lex.start)
            context = pctx.ParserContext(
                name=name, buffer=lex.inputstr, start=position, end=position)

        else:
            context = pctx.ParserContext(
                name=name, buffer=lex.inputstr, start=tok.start,
                end=tok.end)

        return context
예제 #2
0
    def context(self, tok=None, pos: Tuple[int, int, int] = None):
        lex = self.lexer
        name = lex.filename if lex.filename else '<string>'

        if tok is None:
            if pos is None:
                pos = lex.end_of_input
            context = pctx.ParserContext(name=name,
                                         buffer=lex.inputstr,
                                         start=pos[2],
                                         end=pos[2])
        else:
            context = pctx.ParserContext(name=name,
                                         buffer=lex.inputstr,
                                         start=tok.start()[2],
                                         end=tok.end()[2])

        return context
예제 #3
0
파일: parsing.py 프로젝트: zhutony/edgedb
    def context(self, tok=None, pos: (int, int, int) = None):
        lex = self.lexer
        name = lex.filename if lex.filename else '<string>'

        if tok is None:
            if pos is None:
                pos = lex.end_of_input
            position = pctx.SourcePoint(*pos)
            context = pctx.ParserContext(name=name,
                                         buffer=lex.inputstr,
                                         start=position,
                                         end=position)
        else:
            context = pctx.ParserContext(name=name,
                                         buffer=lex.inputstr,
                                         start=pctx.SourcePoint(*tok.start()),
                                         end=pctx.SourcePoint(*tok.end()))

        return context
예제 #4
0
async def _execute_ddl(conn, sql_text):
    try:
        if debug.flags.bootstrap:
            debug.header('Delta Script')
            debug.dump_code(sql_text, lexer='sql')

        await conn.execute(sql_text)

    except Exception as e:
        position = getattr(e, 'position', None)
        internal_position = getattr(e, 'internal_position', None)
        context = getattr(e, 'context', '')
        if context:
            pl_func_line = re.search(
                r'^PL/pgSQL function inline_code_block line (\d+).*',
                context, re.M)

            if pl_func_line:
                pl_func_line = int(pl_func_line.group(1))
        else:
            pl_func_line = None
        point = None

        if position is not None:
            position = int(position)
            point = parser_context.SourcePoint(
                None, None, position)
            text = e.query
            if text is None:
                # Parse errors
                text = sql_text

        elif internal_position is not None:
            internal_position = int(internal_position)
            point = parser_context.SourcePoint(
                None, None, internal_position)
            text = e.internal_query

        elif pl_func_line:
            point = parser_context.SourcePoint(
                pl_func_line, None, None
            )
            text = sql_text

        if point is not None:
            context = parser_context.ParserContext(
                'query', text, start=point, end=point)
            exceptions.replace_context(e, context)

        raise