def analyze_SQL_tags(path): if type(path) is pathlib.Path: otSQL_str = '<SQL>' otSQL = Word(otSQL_str) otSQL_len = len(otSQL_str) ctSQL_str = '</SQL>' ctSQL = Word(ctSQL_str) ctSQL_len = len(ctSQL_str) bag = dict() for i, ln in gen_file_lines(path): ln1 = ln.rstrip() for result, start, end in otSQL.scanString(ln1): if end - start == otSQL_len: bag[i + 1, start + 1] = otSQL_str for result, start, end in ctSQL.scanString(ln1): if end - start == ctSQL_len: bag[i + 1, start + 1] = ctSQL_str #for k in sorted(bag): # print(k, bag[k]) return sorted(bag)
#coding: utf8 from pyparsing import Word, nums, Combine, alphas, Literal, ZeroOrMore, Group, Suppress greet = Word(alphas) + "," + Word(alphas) + "!" greeting = greet.parseString("Hello, World!") print(greeting) text = '1+2=3' integer = Word(nums) # simple unsigned integer try: result1 = integer.parseString(text) print(result1) for tokens, start, end in integer.scanString(text): print(tokens, start, end) except ParseException as pe: print(" No match: {0}".format(str(pe)))