예제 #1
0
파일: sem.py 프로젝트: YauHsien/some_ETL
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)
예제 #2
0
#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)))