本文整理汇总了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