Exemplo n.º 1
0
    def test2(self):
        'cline class, rawline attribute, comment_list method'
        aa = self.assert_
        ae = self.assertEquals
        fl = fortLine()
        cblk = fl.a_line

        p1 = '''
   ! This is a comment
C
c Internal comment
c
* ! another !
d    a possible debugging line
'''
        p1 = p1[1:]
        p1f = buf_iter(StringIO(p1))

        (fln1, rst) = cblk(p1f)

        aa(''.join(flatten(fln1)) == p1)
        ae([chomp(c) for c in fln1], [
            '   ! This is a comment', 'C', 'c Internal comment', 'c',
            '* ! another !', 'd    a possible debugging line'
        ])
Exemplo n.º 2
0
def _fjoin(dta):
    '''take in a pattern match nested seq data structure for a fortran stmt,
    return tuple (rawline,joined_line,internal_comments)

    For fixed format lines:
    a true fortran line dta structure comes in as:
    [initial stmt [continuation_lines]]

    continuation_lines are structures as well:
        [[comments] continuation_line]
    '''
    rawline           = ''.join(flatten(dta))
    internal_comments = []
    (line,c)          = kill_bang_comment(chomp(dta[0]))
    if not c == '':
        internal_comments.append(c)

    for cont in dta[1]:
        if inputLineLength != 0:
            if cont[inputLineLength:] != '':
                print >> sys.stderr, "The following text is being cut because the statement exceeded the specified line length: "+jl[inputLineLength:]
            cont = cont[:inputLineLength]
        internal_comments.extend(cont[0])
        (l,c) = kill_bang_comment(chomp(cont[1])[6:])
        if not c == '':
            internal_comments.append(chomp(c))
        line += l

    return (rawline,line,internal_comments)
Exemplo n.º 3
0
    def testSplit(self):
        '''plus,disj,consume all string'''

        all = self.all
        ae  = self.assertEqual
        p1  = self.p1

        (v,rst) = all(p1)
        vl      = [ ''.join(flatten(l)) for l in v ]
        ae(vl,[ 'cc','scckk','s','c','scckcck','cc','s','sk' ])
        ae(list(rst),[])
Exemplo n.º 4
0
    def testP3(self):
        '''commented continuation for p3'''
        cblk  = self.cblk
        stmt  = self.stmt
        rst   = self.p3
        jj    = self.jj
        ae    = self.assertEqual

        v,rst = cblk(rst)
        ae(v,['c']*2)
        v,rst = stmt(rst)
        ae(v,['s',[[['c']*2,'k'],[[],'k']]])
        v,rst = seq(any,any)(rst)
        ae(jj(v),'sc')
        v,rst = stmt(rst)
        ae(''.join(flatten(v)),'scckcck')
        v,rst = seq(any,any,any)(rst)
        ae(''.join(v),'ccs')
        v,rst = stmt(rst)
        ae(''.join(flatten(v)),'sk')
        ae(list(rst),[])
Exemplo n.º 5
0
    def asm(s):
        sloc = s
        rv = []
        try:
            for a in asms:
                v, sloc = a(sloc)
                rv.append(v)
            return rv, sloc

        except AssemblerException, excp:
            msg = excp.msg + "->seq failure"
            rest = excp.rest.putback(flatten(rv))
            raise AssemblerException(msg, rest)
Exemplo n.º 6
0
def _fjoin(asm):
    '''assemble a logical line from the assembled
    lines come in from the assembler as

    [[continuation]*,primary line]

    continuations are also structured as
    [continued_line, [comments]*]
    '''

    rawline = ''.join(flatten(asm))
    internal_comments = []
    (conts, prim) = asm
    current_line = []
    initial_line = True
    for (cl, comments) in conts:
        if inputLineLength != 0:
            if cl[inputLineLength:] != '':
                print >> sys.stderr, "The following text is being cut because the statement exceeded the specified line length: " + jl[
                    inputLineLength:]
            cl = cl[:inputLineLength]
        index = 0
        eol_comm = None
        (cl, eol_comm) = _process_conts(cl)
        if eol_comm:
            internal_comments.append(eol_comm)
        internal_comments.extend(comments)
        if initial_line:
            cl = kill_cont(cl)
            initial_line = False
        else:
            cl = kill_cont(kill_token_cont(cl))
        current_line.append(cl)
    # dealing with prim
    if not initial_line:
        prim = kill_token_cont(prim)
    prim = chomp(prim)
    (prim, eol_comm) = _process_conts(prim)
    if (dqCount != 0 or sqCount != 0):
        raise Exception('open quotation bug for ' + str(asm))
    if eol_comm:
        internal_comments.append(eol_comm)
    current_line.append(prim)

    joined = ''.join(current_line)
    return (rawline, joined, internal_comments)
Exemplo n.º 7
0
 def __init__(self, dta, lineNumber):
     self.lineNumber = lineNumber
     self.rawline = ''.join(flatten(dta))
Exemplo n.º 8
0
def jjj(dta):
    return ''.join([chomp(x) for x in flatten(dta)])
def process_fort_cmnt(dta, lineNumber, cmnt_list_fn):
    """set the comment's rawline and return the fort statement comment object"""
    obj = cmnt_list_fn(dta, lineNumber)
    obj.rawline = ''.join(flatten(dta))
    return obj