Exemplo n.º 1
0
def parse_l(l, debug, error_file):
    '''
    preprocessing of the line
    '''

    pval = None
    ptype = None

    # if the line is empty
    if not l:
        raise Exception()
    # or does not start with @ 
    if l[0] != '@':
        raise Exception()

    stack = []

    # array element 0
    x = re.search(ERE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'\s%s\s+:\s\@' % n, " E%s :@" % n, l)
        x = re.search(ERE, l)

    # replace op 0
    x = re.search(OPRE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'op\s%s\s*:\s\@' % n, " OP%s :@" % n, l)
        x = re.search(OPRE, l)

    # now try and parse the input
    try:
        x = parser.parse(l, debug=debug)
        
        if not x:
            error_file.write(l + "\n")
            print "Error on Line:%s" % l
            #print "Stack:%s" % stack
            #print "parser %s" % parser
            #if not debug:
            #    x = parser.parse(l, debug=True)
        else:
            report(x,l)
            if debug:
                print("Results1 %s" % x)
            else:
                s = str(x)
                if not s in seen:
                    seen[s]=1
                    if debug:
                        print("Results2 '%s'" % s)

        if debug :
            print "Stack:%s" % stack
            print "parser %s" % parser
    #except QueryBadFormed as e:
    #    raise e
    except Exception as exp:
        print "parse error : "+ l + "\n"
        error_file.write(l + "\n")
        traceback.print_exc()
        print exp
        print "EXP Line:%s" % l
        print "EXP Stack:%s" % stack
        raise exp
Exemplo n.º 2
0
def parse_l(l, debug):
    '''
    preprocessing of the line
    '''

    pval = None
    ptype = None
    if not l:
        raise Exception()
    if l[0] != '@':
        raise Exception()
    stack = []
    # array element 0
    x = re.search(ERE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'\s%s\s+:\s\@' % n, " E%s :@" % n, l)
        x = re.search(ERE, l)
    # replace op 0
    x = re.search(OPRE, l)

    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'op\s%s\s*:\s\@' % n, " OP%s :@" % n, l)
        x = re.search(OPRE, l)
    try:
        lex.input(l)
        for tok in iter(lex.token, None):
            pval = repr(tok.value)
            ptype = repr(tok.type)
            if ptype not in vals:
                vals[ptype] = {}
            vals[ptype][pval] = 1
            stack.append(ptype)  # ,pval

    except Exception as exp:
        print "LEX ERROR %s %s" % (ptype, pval)
        print l
        print exp
        print stack
        # raise exp

    if debug:
        print "Line %s" % l

    try:
        x = parser.parse(l, debug=debug)
        if not x:
            print "Line:%s" % l
            print "Stack:%s" % stack
            print "parser %s" % parser

            if not debug:
                x = parser.parse(l, debug=True)

        else:
            if debug:
                print("Results1 %s" % x)
            else:
                s = str(x)
                if not s in seen:
                    seen[s]=1
                    print("Results2 '%s'" % s)

        if debug :
            print "Stack:%s" % stack
            print "parser %s" % parser


    except Exception as exp:
        traceback.print_exc()
        print exp
        print "EXP Line:%s" % l
        print "EXP Stack:%s" % stack