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


Python Scanner.get方法代码示例

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


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

示例1: Parser

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import get [as 别名]
class Parser(object):

    def parse(self, sourceStr):
        self._completionMessage = "No errors"
        self._parseSuccessful = True
        self._scanner = Scanner(sourceStr)
        self._expression()
        self._accept(self._scanner.get(), Token.EOE,
                     "symbol after end of expression")
   
    def parseStatus(self):
        return self._completionMessage
    
    def _accept(self, token, expected, errorMessage):
        if token.getType() != expected:
            self._fatalError(token, errorMessage)

    def _fatalError(self, token, errorMessage):
        self._parseSuccessful = False
        self._completionMessage = "Parsing error -- " + \
                                  errorMessage + \
                                  "\nExpression so far = " + \
                                  self._scanner.stringUpToCurrentToken()
        raise Exception, self._completionMessage

    def _expression(self):
        """Syntax rule:
        expression = term { addingOperator term }  """           
        self._term()
        token = self._scanner.get()
        while token.getType() in (Token.PLUS, Token.MINUS):
            self._scanner.next()
            self._term()
            token = self._scanner.get()

    def _term(self):
        """Syntax rule:
        term = factor { multiplyingOperator factor }  """           
        self._factor()
        token = self._scanner.get()
        while token.getType() in (Token.MUL, Token.DIV):
            self._scanner.next()
            self._factor()
            token = self._scanner.get()

    def _factor(self):
        """Syntax rule:
        factor = number | "(" expression ")  """"          
        token = self._scanner.get()
        if token.getType() == Token.INT:
            self._scanner.next()
        elif token.getType() == Token.L_PAR:
            self._scanner.next()
            self._expression()
            self._accept(self._scanner.get(),
                         Token.R_PAR,
                         "')' expected")
            self._scanner.next()
        else:
            self._fatalError(token, "bad factor")
开发者ID:gregpuzzles1,项目名称:Sandbox,代码行数:62,代码来源:parsers.py

示例2: consume_text_worker

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import get [as 别名]
def consume_text_worker( params ):

	then 			= datetime.datetime.now()

	offset			= 0
	if OFFSET_KEY in params:
		offset = int( params[ OFFSET_KEY ] )

	text 			= datastore.read_current_blob( offset )
	scanner 		= Scanner( text )
	current_word 	= None
	num_tasks 		= 0 
	pattern			= re.compile( r"[\w']+|[.,!?;]" )
	timeout			= False
	elapsed			= None

	while not timeout and not scanner.eos():
		
		token = scanner.scan( pattern )
		if current_word is not None:
			add_forward_link( current_word, token )
			num_tasks = num_tasks + 1
		current_word = token
		scanner.get()

		elapsed = datetime.datetime.now() - then
		if elapsed >= TASK_TIME:
			offset = scanner.pos 
			add_task( "/tasks/consume_text", { OFFSET_KEY : offset } )
			logging.debug( "consume_text_worker hit timelimit, will resume at offset %d" % offset )
			timeout = True
	
	logging.debug( "scanned %d tokens in %d seconds" % (num_tasks,elapsed.total_seconds() ) )

	if scanner.eos():
		finalise_links()
开发者ID:prehensile,项目名称:verbivore-appengine,代码行数:38,代码来源:tasks.py

示例3: Parser

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import get [as 别名]
class Parser(object):

    def parse(self, sourceStr):
        self._completionMessage = "No errors"
        self._parseSuccessful = True
        self._scanner = Scanner(sourceStr)
        tree = self._expression()
        self._accept(self._scanner.get(), Token.EOE,
                     "symbol after end of expression")
        return tree
   
    def parseStatus(self):
        return self._completionMessage
    
    def _accept(self, token, expected, errorMessage):
        if token.getType() != expected:
            self._fatalError(token, errorMessage)

    def _fatalError(self, token, errorMessage):
        self._parseSuccessful = False
        self._completionMessage = "Parsing error -- " + \
                                  errorMessage + \
                                  "\nExpression so far = " + \
                                  self._scanner.stringUpToCurrentToken()
        raise Exception(self._completionMessage)

    def _expression(self):
        tree = self._term()
        token = self._scanner.get()
        while token.getType() in (Token.PLUS, Token.MINUS):
            op = str(token)
            self._scanner.next()
            tree = InteriorNode(op, tree, self._term())
            token = self._scanner.get()
        return tree

    def _term(self):
        tree = self._factor()
        token = self._scanner.get()
        while token.getType() in (Token.MUL, Token.DIV):
            op = str(token)
            self._scanner.next()
            tree = InteriorNode(op, tree, self._factor())
            token = self._scanner.get()
        return tree

    def _factor(self):
        token = self._scanner.get()
        if token.getType() == Token.INT:
            tree = LeafNode(token.getValue())
            self._scanner.next()
        elif token.getType() == Token.L_PAR:
            self._scanner.next()
            tree = self._expression()
            self._accept(self._scanner.get(),
                         Token.R_PAR,
                         "')' expected")
            self._scanner.next()
        else:
            tree = None
            self._fatalError(token, "bad factor")
        return tree
开发者ID:QaziPython,项目名称:CS-Books,代码行数:64,代码来源:parsers.py

示例4: open

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import get [as 别名]
#!/usr/bin/python
# -*- coding: utf-8 -*-

from scanner import Scanner


f = open('RMLStarReceiptPrinter.h', 'r')

source = f.read()

scanner = Scanner(source)

char = scanner.get()

while (True):
    print char

    if char.content == "\0":
        break

    char = scanner.get()
开发者ID:relishmedia,项目名称:h2md,代码行数:23,代码来源:h2md.py


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