當前位置: 首頁>>代碼示例>>Python>>正文


Python LexToken.type方法代碼示例

本文整理匯總了Python中ply.lex.LexToken.type方法的典型用法代碼示例。如果您正苦於以下問題:Python LexToken.type方法的具體用法?Python LexToken.type怎麽用?Python LexToken.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ply.lex.LexToken的用法示例。


在下文中一共展示了LexToken.type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _lextoken_from_html

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
	def _lextoken_from_html(self, html_token):
		token = LexToken()
		token.type = {
			0 : 'HTML_DOCTYPE',
			1 : 'HTML_CHARS',
			2 : 'HTML_WS',
			3 : 'HTML_STARTTAG',
			4 : 'HTML_ENDTAG',
			5 : 'HTML_EMPTYTAG',
			6 : 'HTML_COMMENT',
			7 : 'HTML_PARSEERROR',
		}[html_token['type']]
		# TODO: fix lineno/lexpos
		token.lineno = self.lineno
		token.lexpos = self.lexpos
		
		token.value = {
			'self_closing' : html_token.get('selfClosing', False),
			'name' : html_token.get('name', None),
		}
		
		if isinstance(html_token['data'], (list, tuple)):
			token.value['attrs'] = html_token['data']
			token.value['data'] = ''
			if token.value['name'].lower() in voidElements:
				token.type = 'HTML_VOID_TAG'
		else:
			token.value['data'] = html_token['data']
		
		if token.type == tokenTypes['ParseError']:
			raise SyntaxError("Got HTML Parse Error for token {}".format(html_token))
		
		return token
開發者ID:Naddiseo,項目名稱:jsdompl,代碼行數:35,代碼來源:htmllexer.py

示例2: p_error

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
def p_error(p):
  """
  print(p.lexer.prev.lineno, p.lineno)
  if p.lexer.prev.lineno < p.lineno or p.type == "RBRACKET":
    yacc.errok()
    return
  """
      
  if p == None:
    if not restricted() and glob.g_tried_semi == False:
      t = LexToken()
      t.type = "SEMI"
      t.value = ";"
      t.lexpos = -1
      t.lineno = -1
      glob.g_lexer.push(t)
      glob.g_tried_semi = True
      yacc.errok()
    else:
      sys.stderr.write(glob.g_file + ": error: unexpected end of file\n")
    return
  else:
    glob.g_error_pre = p
    if handle_semi_error(p):
      t = LexToken()
      t.type = "SEMI"
      t.value = ";"
      t.lexpos = p.lexpos
      t.lineno = p.lineno
      #glob.g_lexer.push(t)
      #glob.g_tried_semi = True
      
      yacc.errok()
      glob.g_error = False
      return
    else:      
      glob.g_error = True
      print_err(p)
      return
      
  if glob.g_error:
    print_err(glob.g_error_pre)
    
  glob.g_error_pre = p
  glob.g_error = True
  
  try:
    line = int(p.lineno)
  except:
    line = p.lineno(1)
  
  try:
    lexdata = p.lexer.lexer.lexdata
    sline = p.lexer.lexer.lexpos
  except:
    lexdata = p.lexer.lexdata
    sline = p.lexer.lexpos
  
  sline = lexdata[sline-40:sline+1]
開發者ID:joeedh,項目名稱:es5parse,代碼行數:61,代碼來源:js_parse.py

示例3: _lextoken

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def _lextoken( self, type_, value ) :
     tok = LexToken()
     tok.type = type_
     tok.value = value
     tok.lineno = self.lexer.lineno
     tok.lexpos = self.lexer.lexpos
     return tok
開發者ID:prataprc,項目名稱:eazytext,代碼行數:9,代碼來源:lexer.py

示例4: _create_token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def _create_token(self, type):
     token = LexToken()
     token.type = type
     token.value = ''
     token.lineno = 0
     token.lexpos = 0
     return token
開發者ID:alangpierce,項目名稱:APPy,代碼行數:9,代碼來源:file_lexer.py

示例5: clone_token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def clone_token(old_token, new_type):
   token = LexToken()
   token.type = new_type
   token.value = old_token.value
   token.lineno = old_token.lineno
   token.lexpos = old_token.lexpos
   return token
開發者ID:MHordecki,項目名稱:easyply,代碼行數:9,代碼來源:parser.py

示例6: _new_token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
def _new_token(type, token):
    tok = LexToken()
    tok.type = type
    tok.value = token.value
    tok.lineno = token.lineno
    tok.lexpos = token.lexpos
    return tok
開發者ID:abadger,項目名稱:Bento,代碼行數:9,代碼來源:lexer.py

示例7: new_dedent

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
def new_dedent(amount, token):
    tok = LexToken()
    tok.type = "DEDENT"
    tok.value = amount
    tok.lineno = token.lineno
    tok.lexpos = token.lexpos
    return tok
開發者ID:davedoesdev,項目名稱:Bento,代碼行數:9,代碼來源:lexer.py

示例8: token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def token(self, value, ty=None):
     t = LexToken()
     t.type = ty if ty != None else value
     t.value = value
     t.lineno = -1
     t.lexpos = -1
     return t
開發者ID:ShishKabab,項目名稱:python-jsonpath-rw,代碼行數:9,代碼來源:test_lexer.py

示例9: _to_yacc

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def _to_yacc(self, token_type, token_data):
     token = LexToken()
     token.type = token_type
     token.value = (token_type, token_data)
     token.lineno = 0 # TODO: file offset
     token.lexpos = 0
     self.__to_yacc(token)
開發者ID:vpelletier,項目名稱:ITI1480A-linux,代碼行數:9,代碼來源:parser.py

示例10: gen

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
def gen(code):
	for line in code:
		for item in line:
			t = LexToken()
			t.type = item[1]
			t.value = item[0]
			yield t
	yield None
開發者ID:koo5,項目名稱:secret-banana,代碼行數:10,代碼來源:parser.py

示例11: createFunctionDefinition

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def createFunctionDefinition(self, def_token, var_token, params, val_node):
    lamToken = LexToken()
    lamToken.value = 'lambda'
    lamToken.type = 'LAMBDA'
    return LetNode(def_token, [ 
         VariableNode(var_token),
         LambdaNode(lamToken, [ Node(None, None, nodes(params)), val_node ]), 
         ])
開發者ID:z-lang,項目名稱:z-lang,代碼行數:10,代碼來源:SyntaxTreeFactory.py

示例12: newtok

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def newtok(tok, ttype=None):
     if tok.type != ttype and (ttype != None or tok.value != ""):
         if tok.type != None:
             push(tok)
         tok = LexToken()
         tok.type = ttype
         tok.value = ""
     return tok
開發者ID:joeedh,項目名稱:webblender,代碼行數:10,代碼來源:js_ast_match_lex.py

示例13: _parse_chars

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
	def _parse_chars(self, data):
		m = js_start_rx.match(data)
		
		if m is None:
			return None
		
		pretext = m.group(1)
		start_type = m.group(2)
		
		self.lexpos -= len(data)
		
		if len(pretext):
			pretext_tok = LexToken()
			pretext_tok.type = 'HTML_CHARS'
			pretext_tok.value = pretext
			pretext_tok.lineno = self.lineno - pretext.count("\n")
			pretext_tok.lexpos = self.lexpos
			self.next_tokens.append(pretext_tok)
			self.lexpos += len(pretext)
		
		start_tok = LexToken()
		start_tok.type = self.tbtype[start_type]
		start_tok.value = start_type
		start_tok.lineno = self.lineno
		start_tok.lexpos = self.lexpos
		self.next_tokens.append(start_tok)
		self.lexpos += len(start_type)
		
		js_lexer = JSLexer()
		js_lexer.input(data[m.end(2):])
		for t in js_lexer:
			t.lineno += self.lineno - 1
			t.lexpos = self.lexpos
			self.lexpos += js_lexer.lexer.lexpos
			
			if t.type in ('EXPRESSION_TERMINATOR', 'ESCAPED_TERMINATOR', 'JS_TERMINATOR'):
				if t.type != self.ttype[start_type]:
					raise SyntaxError("Expected {} but got {} in char data `{}`".format(self.ttype[start_type], t.type, data))
				self.next_tokens.append(t)
				break
			
			self.next_tokens.append(t)
		remaining_text = data[m.end(2) + js_lexer.lexer.lexpos:]
		self.lexpos += len(remaining_text)
		return remaining_text
開發者ID:Naddiseo,項目名稱:jsdompl,代碼行數:47,代碼來源:htmllexer.py

示例14: gen_token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
    def gen_token(value, type, line, lexpos):
        t = LexToken()
        t.value = value
        t.type = type
        t.line = line
        t.lexpos = lexpos
        t.lexer = self

        return t
開發者ID:joeedh,項目名稱:webblender,代碼行數:11,代碼來源:js_ast_match_lex.py

示例15: _new_token

# 需要導入模塊: from ply.lex import LexToken [as 別名]
# 或者: from ply.lex.LexToken import type [as 別名]
 def _new_token(self, type=None, value=None, lexpos=None, lineno=None) -> LexToken:
     """
     Creates a new lexer token with the given properties.
     :return: a new lexer token with the given properties.
     """
     token = LexToken()
     token.type = type
     token.value = value
     token.lexpos = lexpos
     token.lineno = lineno
開發者ID:outofbits,項目名稱:linkedPy,代碼行數:12,代碼來源:lexer_wrapper.py


注:本文中的ply.lex.LexToken.type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。