Ejemplo n.º 1
0
 def __init__(self, csv):
     SE_scanner = Scanner(STRING=r'"((?:\\["\tvbnr]|[^\"])*)"',
                          AND=r"\band\b",
                          OR=r"\bor\b",
                          NOT=r"\bnot\b",
                          EQ="=",
                          COMMA=",",
                          MATCHES=r"\bmatches\b",
                          CONTAINS=r"\bcontains\b",
                          OPEN_PAR="[(]",
                          CLOSE_PAR="[)]",
                          _whitespace=r"[ \r\n\t]+",
                         discard_names=["_whitespace"])
     SE_scanner.add(WHATEVER=r"[^ ,\r\n\t=()]+")
     Automaton.__init__(self, "where", SE_grammar, SE_scanner)
     if csv.headers:
         self.colnames = dict((k, v)
                              for v in xrange(len(csv.headers))
                              for k in (v + 1, str(v + 1), csv.headers[v]))
     else:
         self.colnames = dict((k, i)
                              for i in xrange(len(csv.data[0]))
                              for k in (str(i + 1), i + 1))
     self.val = {
         'p1': self.p1,
         'p2': self.p2,
         'p3': self.p3,
         'p4': self.p4,
         'colset': self.colset,
         'valueset': self.valueset,
     }
Ejemplo n.º 2
0
 def __init__(self, csv):
     SE_scanner = Scanner(STRING=r'"((?:\\["\tvbnr]|[^\"])*)"',
                          AND=r"\band\b",
                          OR=r"\bor\b",
                          NOT=r"\bnot\b",
                          EQ="=",
                          COMMA=",",
                          MATCHES=r"\bmatches\b",
                          CONTAINS=r"\bcontains\b",
                          OPEN_PAR="[(]",
                          CLOSE_PAR="[)]",
                          _whitespace=r"[ \r\n\t]+",
                          discard_names=["_whitespace"])
     SE_scanner.add(WHATEVER=r"[^ ,\r\n\t=()]+")
     Automaton.__init__(self, "where", SE_grammar, SE_scanner)
     if csv.headers:
         self.colnames = dict((k, v) for v in xrange(len(csv.headers))
                              for k in (v + 1, str(v + 1), csv.headers[v]))
     else:
         self.colnames = dict((k, i) for i in xrange(len(csv.data[0]))
                              for k in (str(i + 1), i + 1))
     self.val = {
         'p1': self.p1,
         'p2': self.p2,
         'p3': self.p3,
         'p4': self.p4,
         'colset': self.colset,
         'valueset': self.valueset,
     }
Ejemplo n.º 3
0
    def __init__(self):
        from time import time

        t0 = time()
        Automaton.__init__(self, "script", R_grammar, r_scanner)
        self.resolve_SR_conflicts(favor="S")
        self.build_time = time() - t0
Ejemplo n.º 4
0
 def __call__(self, filename=None, text=None):
     if text is None and filename is not None:
         RContext.current_text.append(open(filename).read())
         #RContext.current_dir.append(os.path.dirname(filename))
     elif text is not None:
         filename = '<text>'
         RContext.current_text.append(text)
         #RContext.current_dir.append(RContext.current_dir[-1])
     else:
         return None
     print "Parsing", filename
     RContext.current_file.append(filename)
     try:
         ret = Automaton.__call__(self, RContext.current_text[-1])
     except:
         import traceback
         traceback.print_exc()
         ret = None
     RContext.current_file.pop()
     RContext.current_text.pop()
     #RContext.current_dir.pop()
     return ret
Ejemplo n.º 5
0
    def __call__(self, filename=None, text=None):
        if text is None and filename is not None:
            RContext.current_text.append(open(filename).read())
            # RContext.current_dir.append(os.path.dirname(filename))
        elif text is not None:
            filename = "<text>"
            RContext.current_text.append(text)
            # RContext.current_dir.append(RContext.current_dir[-1])
        else:
            return None
        print "Parsing", filename
        RContext.current_file.append(filename)
        try:
            ret = Automaton.__call__(self, RContext.current_text[-1])
        except:
            import traceback

            traceback.print_exc()
            ret = None
        RContext.current_file.pop()
        RContext.current_text.pop()
        # RContext.current_dir.pop()
        return ret
Ejemplo n.º 6
0
 def __init__(self):
     from time import time
     t0 = time()
     Automaton.__init__(self, "script", R_grammar, r_scanner)
     self.resolve_SR_conflicts(favor='S')
     self.build_time = time() - t0
Ejemplo n.º 7
0
 def __init__(self, start='translation_unit'):
     t0 = time()
     Automaton.__init__(self, start, grammar, cpp_scanner)
     t1 = time()
     self.build_time = t1 - t0
     self.debug = True
Ejemplo n.º 8
0
Archivo: parser.py Proyecto: bl0b/cppy
 def __init__(self):
     Automaton.__init__(self, start_symbol, grammar, cpp_scanner)
     self.scope_stack = [{}]
     self.root = ns.root()
     self.ns = self.root