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


Python Stream.eof方法代码示例

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


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

示例1: Scanner

# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]
class Scanner(object):
    def initialize_scan(self, string):
        self.tokens = []
        self.stream = Stream(string)

    def produce(self, token):
        self.tokens.append(token)

    def tokenize(self):
        while self.tokenize_one():
            pass
        return self.tokens

    def tokenize_one(self):
        i = self.stream.index

        if self.stream.eof():
            self.eof()
            return False

        for tokenizer_pair in self.state:
            tokenizer = tokenizer_pair[0]
            action = tokenizer_pair[1]
            if tokenizer.applies(self.stream):
                j = self.stream.index
                action(self, tokenizer.token(self.stream, i, j))
                return True

        raise StandardError("No tokenizer applied.")
开发者ID:diiq,项目名称:oyoy,代码行数:31,代码来源:scanner.py

示例2: ParseError

# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]
class Tokenizer:
    class ParseError(RuntimeError):
        pass

    class ModuleError(RuntimeError):
        pass

    def parse(self, src):
        self.strm = Stream(src)
        self.tokens = []

        s = self.strm
        m = 'text block'
        buf = ''
        while not s.eof():
            c = s.get()
            if m == 'text block':
                if c == '{' and s.cur() == '@':
                    if len(buf):
                        self.tokens.append(Token(kind='text-block', value=buf))
                        buf = ''
                    s.get()
                    self.tokens.append(Token(kind='lbraceat', value='{@'))
                    m = 'code block'
                elif c == '{' and s.cur() == '{':
                    if len(buf):
                        self.tokens.append(Token(kind='text-block', value=buf))
                        buf = ''
                    s.get()
                    self.tokens.append(Token(kind='ldbrace', value='{{'))
                    m = 'ref block'
                else:
                    buf += c
            elif m == 'ref block':
                if c == '}' and s.cur() == '}':
                    s.get()
                    self.tokens.append(Token(kind='rdbrace', value='}}'))
                    m = 'text block'                    
                elif self.is_identifier_char(c):
                    s.prev()
                    self.read_identifier()
                elif c == '(':
                    self.tokens.append(Token(kind='lparen', value='('))
                elif c == ')':
                    self.tokens.append(Token(kind='rparen', value=')'))
                elif c == '.':
                    self.tokens.append(Token(kind='operator', value='.'))
                elif c == '"':
                    s.prev()
                    self.read_string()
            elif m == 'code block':
                if c == '@' and s.cur() == '}':
                    s.get()
                    self.tokens.append(Token(kind='rbraceat', value='@}'))
                    m = 'text block'
                elif c == '.':
                    self.tokens.append(Token(kind='operator', value='.'))
                elif c == ',':
                    self.tokens.append(Token(kind='comma', value=','))
                elif c == '(':
                    self.tokens.append(Token(kind='lparen', value='('))
                elif c == ')':
                    self.tokens.append(Token(kind='rparen', value=')'))
                elif c == ':':
                    self.tokens.append(Token(kind='colon', value=':'))
                elif c == '=':
                    s.prev()
                    self.read_assign()
                elif c == '!':
                    s.prev()
                    self.read_not()
                elif c == '<':
                    s.prev()
                    self.read_lt()
                elif c == '>':
                    s.prev()
                    self.read_gt()
                elif c == '+':
                    s.prev()
                    self.read_add()
                elif c == '-':
                    s.prev()
                    self.read_sub()
                elif c == '*':
                    self.tokens.append(Token(kind='operator', value='*'))
                elif c == '/':
                    self.tokens.append(Token(kind='operator', value='/'))
                elif c == '"':
                    s.prev()
                    self.read_string()
                elif c.isdigit():
                    s.prev()
                    self.read_digit()
                elif self.is_identifier_char(c):
                    s.prev()
                    self.read_identifier()
                elif c.isspace():
                    pass
                else:
                    raise Tokenizer.ParseError('unsupprted character %s' % c)
#.........这里部分代码省略.........
开发者ID:narupo,项目名称:cap,代码行数:103,代码来源:tokenizer.py

示例3: ModuleError

# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import eof [as 别名]

#.........这里部分代码省略.........
            raise AST.NameError('"%s" is not defined' % first)

    def call_alias_package(self, node):
        if not self.context.imported_alias:
            raise AST.ImportError('alias is not imported')

        method = node.identifiers[1]
        if method == 'set':
            if len(node.args) != 2:
                AST.SyntaxError('alias.set need two arguments')
            name = node.args[0]
            cmd = node.args[1]
            self.context.alias_map[name] = cmd

    def call_config_package(self, node):
        if not self.context.imported_config:
            raise AST.ImportError('config is not imported')

        method = node.identifiers[1]
        if method == 'set':
            if len(node.args) != 2:
                AST.SyntaxError('config.set need two arguments')
            name = node.args[0]
            cmd = node.args[1]
            self.context.config_map[name] = cmd

    def show_parse(self, name, dep):
        if self.debug_parse:
            t = self.strm.cur()
            print(dep, name + ': ' + str(t))

    def block(self, dep=0):
        self.show_parse('block', dep=dep)
        if self.strm.eof():
            return None
        
        t = self.strm.cur()
        if t.kind in ('rbraceat', 'end', 'if', 'elif', 'else'):
            return None

        node = BlockNode()

        node.code_block = self.code_block(dep=dep+1)
        if node.code_block is None:
            node.ref_block = self.ref_block(dep=dep+1)
            if node.ref_block is None:
                node.text_block = self.text_block(dep=dep+1)

        node.block = self.block(dep=dep+1)
        return node

    def ref_block(self, dep=0):
        self.show_parse('ref_block', dep=dep)
        if self.strm.eof():
            return None

        node = RefBlockNode()

        t = self.strm.get()
        if t.kind != 'ldbrace':
            self.strm.prev()
            return None

        t = self.strm.get()
        if t.kind == 'identifier':
            t2 = self.strm.cur()
开发者ID:narupo,项目名称:cap,代码行数:70,代码来源:ast.py


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