コード例 #1
0
    def setUp(self):
        self.p1 = buf_iter('ccscckkscscckcckccssk')
        self.ee = buf_iter([])
        (s, k, c) = [mkpred(l) for l in 'skc']

        self.stmt = seq(s, star(seq(star(c), k)))
        self.cblk = plus(c)
        self.all = star(disj(self.cblk, self.stmt))
コード例 #2
0
    def setUp(self):
        self.p1 = buf_iter('ssskkss')
        self.p2 = buf_iter('ccscssscskkskscskskksss')
        self.p3 = buf_iter('ccscckkscscckcckccssk')

        self.ss = mkpred('s')
        self.k = mkpred('k')
        self.c = mkpred('c')

        ss = self.ss
        k = self.k
        c = self.c

        self.cblk = star(c)
        self.stmt = seq(ss, star(seq(star(c), k)))
コード例 #3
0
    def test4(self):
        'incremental side effect build 1 unit w 2 subunits'
        uu = self.uu
        ts = '''ua cd1 d1 cx1 x1 cn1 n
                   cnu1 un1 cn1d dn1 cnx1 xn1 cne en
                   unb db1 db2 xb1 xb2 xb3 eb
                 e1'''
        ii = buf_iter((i for i in ts.split()))
        (u, r) = uu(ii)
        ae(list(r), [])
        ae(u.cmnt, None)
        ae(u.decls, ['cd1', 'd1'])
        ae(u.contains, ['cn1', 'n'])
        ae(len(u.ulist), 2)
        ae(u.end, ['e1'])

        (u, u2) = u.ulist
        a_(isinstance(u, _T))
        ae(u.cmnt, 'cnu1')
        ae(u.unit, 'un1')
        ae(u.execs, ['cnx1', 'xn1'])
        u = u2
        a_(isinstance(u, _T))
        ae(u.cmnt, None)
        ae(u.unit, 'unb')
        ae(u.execs, ['xb1', 'xb2', 'xb3'])
        ae(u.end, ['eb'])
コード例 #4
0
    def test1(self):
        'vgen gets all assemblies from a file'
        ae = self.assertEqual
        aiter = vgen(self.asem, buf_iter(self.f))

        asems = list(aiter)

        ae(asems, ['skk', 's', 's', 'ccc'])
コード例 #5
0
    def setUp(self):
        strng = mkpred('string')
        no = mkpred('no')

        self.strng = strng
        self.no = no

        self.t1 = buf_iter(
            ['string', 'string', 'string', 'no', 'string', 'string'])
        self.t2 = buf_iter(['no', 'string', 'no', 'no'])
        self.t3 = buf_iter(
            ['string', 'no', 'string', 'no', 'string', 'string'])

        self.seq1 = seq(no, strng)
        self.seq2 = seq(star(self.strng), no, strng)
        self.seq3 = seq(star(strng), no, star(strng))
        self.asm3 = star(seq(strng, no))
コード例 #6
0
def fortUnitIterator(fileName, inputFormat=None):
    '''
    returns an iterator over units found in the given file named fileName;
    the units are assembled based on install_pat
    and buf_iter provides the source iterator from which the units are assembled
    '''
    return vgen(install_pat(_curr(module_handler.ourModuleHandler)),
                buf_iter(Ffile.file(fileName,parse_cmnt,parse_stmts,\
                                    inputFormat).lines))
コード例 #7
0
 def test2(self):
     'incremental side effect build vgen f 2 simple units'
     uu = self.uu
     ts = 'ua c1 d1 c3 x1 e1 cb ub cdb1 db1 cxb1 xb1 xb2 eb'
     ii = buf_iter((i for i in ts.split()))
     units = list(vgen(uu, ii))
     ae(len(units), 2)
     (u1, u2) = units
     ae(u1.cmnt, None)
     ae(u2.execs, ['cxb1', 'xb1', 'xb2'])
コード例 #8
0
 def asm(s):
     try:
         v = s.next()
     except StopIteration:
         raise AssemblerException('Empty Assembly', buf_iter(iter([])))
     try:
         if p(v):
             return (v, s)
     except:
         pass
     raise AssemblerException('Predicate Failure', s.putback([v]))
コード例 #9
0
 def test1(self):
     'incremental side effect build f simple unit'
     uu = self.uu
     ts = 'c1 u1 d1 x1 e1'
     ii = buf_iter((i for i in ts.split()))
     (v, r) = uu(ii)
     a_(isinstance(v, _T))
     a_(not list(r))
     ae(v.cmnt, 'c1')
     ae(v.unit, 'u1')
     ae(v.decls, ['d1'])
     ae(v.execs, ['x1'])
     ae(v.contains, [])
     ae(v.ulist, [])
     ae(v.end, ['e1'])
コード例 #10
0
    def testF1(self):
        '''read line assemblies from file'''
        ae = self.assertEqual
        rst = buf_iter(self.f)
        stmt = self.stmt
        cblk = self.cblk

        (v, rst) = stmt(rst)
        ae(jjj(v), 'skk')
        (v, rst) = stmt(rst)
        ae(jjj(v), 's')
        (v, rst) = stmt(rst)
        ae(jjj(v), 's')
        (v, rst) = cblk(rst)
        ae(jjj(v), 'ccc')
        ae(list(rst), [])
コード例 #11
0
    def test3(self):
        'incremental side effect build w recursive pattern'
        uu = self.uu
        ts = 'ua cd1 d1 cx1 x1 cn1 n cnu1 un1 cn1d dn1 cnx1 xn1 cne en e1'
        ii = buf_iter((i for i in ts.split()))
        (u, r) = uu(ii)
        ae(list(r), [])
        ae(u.cmnt, None)
        ae(u.decls, ['cd1', 'd1'])
        ae(u.contains, ['cn1', 'n'])
        ae(len(u.ulist), 1)
        ae(u.end, ['e1'])

        u = u.ulist[0]
        a_(isinstance(u, _T))
        ae(u.cmnt, 'cnu1')
        ae(u.unit, 'un1')
        ae(u.execs, ['cnx1', 'xn1'])
コード例 #12
0
    def __init__(self,
                 fobj,
                 free=False,
                 c_action=cline,
                 s_action=fline,
                 isTemp=False):
        fmt = (free and freefmt) or fixedfmt
        fl = fortLine(fmt)
        s = lambda x: process_fort_stmt(x, self.rawBufIter.myCounter, s_action)
        c = lambda x: process_fort_cmnt(x, self.rawBufIter.myCounter, c_action)
        cblk = treat(fl.cblk, c)
        # produces multiple statements, if multiple statements were on
        # the same line in the original file
        stmt = treat(fl.stmt, s)
        a_line = disj(cblk, stmt)

        self.rawBufIter = buf_iter(fobj)
        self.lines = vgen(a_line, self.rawBufIter, True)
        self.fobj = fobj
        self.isTemp = isTemp
コード例 #13
0
    def test5(self):
        'incremental side effect build 1 unit w subunits having subunits'
        uu = self.uu
        ts = '''umod
                   dm1 dm2 nmod
                     ua cd1 d1 cx1 x1 cn1 n
                      cnu1 un1 cn1d dn1 cnx1 xn1 cne eun1
                      unb db1 db2 xb1 xb2 xb3 eb
                     ea
                 emod'''

        ii = buf_iter((i for i in ts.split()))
        (u, r) = uu(ii)
        ae(list(r), [])
        ae(u.cmnt, None)
        ae(u.decls, ['dm1', 'dm2'])
        ae(u.contains, ['nmod'])
        ae(len(u.ulist), 1)
        ae(u.end, ['emod'])

        u = u.ulist[0]
        a_(isinstance(u, _T))
        ae(u.cmnt, None)
        ae(u.unit, 'ua')
        ae(u.execs, ['cx1', 'x1'])
        ae(len(u.ulist), 2)
        ae(u.end, ['ea'])

        (u, u2) = u.ulist
        a_(isinstance(u, _T))
        ae(u.cmnt, 'cnu1')
        ae(u.unit, 'un1')
        ae(u.execs, ['cnx1', 'xn1'])
        u = u2
        a_(isinstance(u, _T))
        ae(u.cmnt, None)
        ae(u.unit, 'unb')
        ae(u.execs, ['xb1', 'xb2', 'xb3'])
        ae(u.end, ['eb'])
コード例 #14
0
def fortPreUnitIterator(fileName,free):
    if free: inputFormat = 'free'
    else: inputFormat = 'fixed'
    return vgen(unit,buf_iter(Ffile.file(fileName,parse_cmnt,parse_stmts,inputFormat).lines))