本文整理匯總了Python中pyparsing.Keyword.scanString方法的典型用法代碼示例。如果您正苦於以下問題:Python Keyword.scanString方法的具體用法?Python Keyword.scanString怎麽用?Python Keyword.scanString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyparsing.Keyword
的用法示例。
在下文中一共展示了Keyword.scanString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: contains_keyword
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import scanString [as 別名]
def contains_keyword(text, query_keyword, atStart=False):
"""test presence of the keyword query_keyword with regard to surrounding unicode characters
if atStart=True, this function success only if text starts with query_keyword
"""
keyword = Keyword(query_keyword)
for token in keyword.scanString(text):
if atStart and token[1]:
return False
if not text[token[1] - 1:token[1]].isalnum() and not text[token[2]:token[2] + 1].isalnum():
return True
return False
示例2: func1
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import scanString [as 別名]
#
# cLibHeader.py
#
# A simple parser to extract API doc info from a C header file
#
# Copyright, 2012 - Paul McGuire
#
from pyparsing import Word, alphas, alphanums, Combine, oneOf, Optional, delimitedList, Group, Keyword
testdata = """
int func1(float *vec, int len, double arg1);
int func2(float **arr, float *vec, int len, double arg1, double arg2);
"""
ident = Word(alphas, alphanums + "_")
vartype = Combine( oneOf("float double int char") + Optional(Word("*")), adjacent = False)
arglist = delimitedList(Group(vartype("type") + ident("name")))
functionCall = Keyword("int") + ident("name") + "(" + arglist("args") + ")" + ";"
for fn,s,e in functionCall.scanString(testdata):
print fn.name
for a in fn.args:
print " - %(name)s (%(type)s)" % a