Example #1
0
def ScannerFactory(name=None,lines=None,format=None,maxcols=None,
                   project=None):
  """ return an instance of scanner. try to be clever, eg
      work out whether to use fixed or free form, set
      provide a set of lines instead of a file if testing
      is being done, etc """

  use_format = "fixed"
  use_maxcols = 72

  if name:
    if not project:
      # Avoid circular references: project -> Scanner -> project
      from Tools.Project import Project
      project = Project()
      
    dFileOpt = project.dGetFileOptions(name)
    # is it fixed or free format?
    if name[-1] == '0': # f90, F90, ...?
      use_format  = dFileOpt.get("format","free")
      use_maxcols = dFileOpt.get("linelength",132)
    else:
      use_format  = dFileOpt.get("format","fixed")
      use_maxcols = dFileOpt.get("linelength",72)

  # explicit format overrides the guess
  if format:
    use_format = format

  if maxcols:
    use_maxcols = maxcols

  if use_format=="free":
    return FreeformScanner(name,use_maxcols,lines, project)
  else:
    return FixedformScanner(name,use_maxcols,lines, project)
Example #2
0
File: format.py Project: hiker/stan
#!/usr/bin/env python

import string
from Stylesheets.Default   import DefaultStylesheet

class MyStyle(DefaultStylesheet):
    
    def __init__(self):
        DefaultStylesheet.__init__(self, 'free')
        self['keywordcase'   ] = 'upper'
        self['variablecase'  ] = 'lower'
        self['contlinemarker'] = '>'
        self["maxcols"       ] = 72
     
# ==============================================================================

if __name__=="__main__":
    import sys
    from Tools.Project import Project

    project = Project()
    ssheet  = MyStyle()
    for i in sys.argv[1:]:
        o = project.oGetObjectForIdentifier(i, "file")
        print ssheet.ToString(o)
    
Example #3
0
File: Dump.py Project: hiker/stan
                lWhenDump = map(int,l)
            except ValueError:
                Usage()
        elif sKey=="-m":
            bDoMPI=1
        elif sKey=="-l":
            l = string.split(sVal,"-",1)
            if len(l)==1:
                try:
                    nLineFrom=nLineTo=int(l[0])
                except ValueError:
                    Usage()
            else:
                try:
                    nLineFrom=int(l[0])
                    nLineTo=int(l[1])
                except ValueError:
                    Usage()

    # There must be exactly one filename
    if len(lArgs)!=1:
        Usage()
    sFilename = lArgs[0]
    project = Project()
    #    try:
    objFile = project.oGetObjectForIdentifier(sFilename, "file")
    #except:
    #print "Errors parsing file '%s'."%sFilename
        
    Dump(objFile, nLineFrom, nLineTo, lWhenDump, bDoMPI=bDoMPI)