当前位置: 首页>>代码示例>>Python>>正文


Python Location.update方法代码示例

本文整理汇总了Python中location.Location.update方法的典型用法代码示例。如果您正苦于以下问题:Python Location.update方法的具体用法?Python Location.update怎么用?Python Location.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在location.Location的用法示例。


在下文中一共展示了Location.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_location

# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import update [as 别名]
    def get_location(self, position):
        loc = Location(self.source_name, 0, 0, 0)
        loc.update(self.data[:position])

        return loc
开发者ID:bazsi,项目名称:codega,代码行数:7,代码来源:lexer.py

示例2: Lexer

# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import update [as 别名]
class Lexer(object):
    '''Custom, ply-based lexer. Takes the tokens the same way the ply
    lexer takes but makes some extra additional comfort features.'''

    source_name = None
    error_context = None
    lexer_object = None
    current_location = None

    error_tokens = None
    warning_tokens = None

    error_message = 'Invalid token: @[email protected]'

    token_list = None

    def __init__(self, source_name, error_context):
        self.source_name = source_name
        self.error_context = error_context
        self.current_location = Location(self.source_name, 0, 0, 0)
        self.data = ''

        # Create logger for lexer
        self.log = logger.getLogger('lexer-%d' % logger.sysid(self))

        # Create ply lexer object
        log_wrapper = logger.PlyLoggerWrapping(self.log)
        self.lexer_object = lex.lex(module=self, debuglog=log_wrapper, errorlog=log_wrapper, debug=1)

        self.log.info('Created lexer; class ID=lexer-class-%d' % logger.sysid(self.__class__))

    @property
    def lineno(self):
        if self.lexer_object is None:
            return None

        return self.lexer_object.lineno

    @property
    def lexpos(self):
        if self.lexer_object is None:
            return None

        return self.lexer_object.lexpos

    def get_location(self, position):
        loc = Location(self.source_name, 0, 0, 0)
        loc.update(self.data[:position])

        return loc

    def input(self, data):
        self.data = data
        self.lexer_object.input(data)
        self.log.debug('Lexer got input; length=%d' % len(data))

    def token(self):
        prev_pos = self.lexer_object.lexpos

        token = self.lexer_object.token()
        if token is not None:
            token.location = self.current_location.clone()
            self.log.debug('Got next token; value=%r, type=%s, location=%s' % (token.value, token.type, token.location))

        else:
            self.log.debug('End of file reached; location=%s' % self.current_location)

        data = self.lexer_object.lexdata[prev_pos:self.lexer_object.lexpos]
        self.current_location.update(data)

        if token is not None:
            if token.type in self.error_tokens:
                error = replace(self.error_tokens[token.type], type=token.type, value=token.value, location=token.location)
                self.error_context.error(error, token.location)
                self.log.error(error)
                return None

            if token.type in self.warning_tokens:
                warning = replace(self.warning_tokens[token.type], type=token.type, value=token.value, location=token.location)
                self.error_context.warning(warning, token.location)
                self.log.warning(warning)

        return token

    def ignore_token(self, token):
        self.log.debug('Ignoring token; value=%r, type=%s, location=%s' % (token.value, token.type, self.current_location))

    @property
    def tokens(self):
        return self.token_list

    def t_error(self, t):
        token = t.value[0]
        self.error_context.error(replace(self.error_message, token=token), self.current_location.clone())

        self.lexer_object.skip(len(token))
        self.log.error('Error parsing character %r' % token)
开发者ID:bazsi,项目名称:codega,代码行数:99,代码来源:lexer.py


注:本文中的location.Location.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。