当前位置: 首页>>代码示例>>Python>>正文


Python ZeroOrMore.parseFile方法代码示例

本文整理汇总了Python中pyparsing.ZeroOrMore.parseFile方法的典型用法代码示例。如果您正苦于以下问题:Python ZeroOrMore.parseFile方法的具体用法?Python ZeroOrMore.parseFile怎么用?Python ZeroOrMore.parseFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.ZeroOrMore的用法示例。


在下文中一共展示了ZeroOrMore.parseFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]
    def read(self, file_or_filename):
        """ Parses a PSAT data file and returns a case object

            file_or_filename: File object or path to PSAT data file
            return: Case object
        """
        self.file_or_filename = file_or_filename

        logger.info("Parsing PSAT case file [%s]." % file_or_filename)

        t0 = time.time()

        self.case = Case()

        # Name the case
        if isinstance(file_or_filename, basestring):
            name, _ = splitext(basename(file_or_filename))
        else:
            name, _ = splitext(file_or_filename.name)

        self.case.name = name

        bus_array = self._get_bus_array_construct()
        line_array = self._get_line_array_construct()
        # TODO: Lines.con - Alternative line data format
        slack_array = self._get_slack_array_construct()
        pv_array = self._get_pv_array_construct()
        pq_array = self._get_pq_array_construct()
        demand_array = self._get_demand_array_construct()
        supply_array = self._get_supply_array_construct()
        # TODO: Varname.bus (Bus names)

        # Pyparsing case:
        case = \
            ZeroOrMore(matlab_comment) + bus_array + \
            ZeroOrMore(matlab_comment) + line_array + \
            ZeroOrMore(matlab_comment) + slack_array + \
            ZeroOrMore(matlab_comment) + pv_array + \
            ZeroOrMore(matlab_comment) + pq_array + \
            ZeroOrMore(matlab_comment) + demand_array + \
            ZeroOrMore(matlab_comment) + supply_array

        case.parseFile(file_or_filename)

        elapsed = time.time() - t0
        logger.info("PSAT case file parsed in %.3fs." % elapsed)

        return self.case
开发者ID:Waqquas,项目名称:pylon,代码行数:50,代码来源:psat.py

示例2: parse_cp2k_warnings

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]
def parse_cp2k_warnings(file_name, package_warnings):
    """
    Parse All the warnings found in an output file
    """
    p = ZeroOrMore(Suppress(SkipTo("*** WARNING")) + SkipTo('\n\n'))

    # Return dict of Warnings
    messages = p.parseFile(file_name).asList()

    # Search for warnings that match the ones provided by the user
    warnings = {m: assign_warning(package_warnings, m) for m in messages}

    if not warnings:
        return None
    else:
        return warnings
开发者ID:SCM-NV,项目名称:qmworks,代码行数:18,代码来源:cp2KParser.py

示例3: guess_language

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]
def guess_language(string=None, filename=None):
    """
    Attempt to guess the language

    Do this by parsing the comments at the top of the file for the

        # language: fr

    phrase.
    """

    LANG_PARSER = ZeroOrMore(
        Suppress('#') + (
            ((Suppress(Keyword('language')) + Suppress(':') +
              Word(unicodePrintables)('language')) |
             Suppress(restOfLine))
        )
    )

    try:
        if string:
            tokens = LANG_PARSER.parseString(string)
        elif filename:
            with open(filename, 'r', 'utf-8') as fp:
                tokens = LANG_PARSER.parseFile(fp)
        else:
            raise RuntimeError("Must pass string or filename")

        code = tokens.language

        if code != '':
            return languages.Language(code=code)

    except ParseException as e:
        # try English
        pass

    return languages.English()
开发者ID:raitisdembovskis,项目名称:lettuce,代码行数:40,代码来源:parser.py

示例4: open

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]
pathToHeader = sys.argv[2] + '.h'
namespace = sys.argv[3]
ddlFile = open(pathToDdl, 'r')
header = open(pathToHeader, 'w')

print('#ifndef '+get_include_guard_name(namespace, pathToHeader), file=header)
print('#define '+get_include_guard_name(namespace, pathToHeader), file=header)
print('', file=header)
print('#include <' + INCLUDE + '/table.h>', file=header)
print('#include <' + INCLUDE + '/column_types.h>', file=header)
print('#include <' + INCLUDE + '/char_sequence.h>', file=header)
print('', file=header)
print('namespace ' + namespace, file=header)
print('{', file=header)

tableCreations = ddl.parseFile(pathToDdl)

for tableCreation in tableCreations:
    sqlTableName = tableCreation.create.tableName
    tableClass = toClassName(sqlTableName)
    tableMember = toMemberName(sqlTableName)
    tableNamespace = tableClass + '_'
    tableTemplateParameters = tableClass
    print('  namespace ' + tableNamespace, file=header)
    print('  {', file=header)
    for column in tableCreation.create.columns:
        if column.isConstraint:
            continue
        sqlColumnName = column[0]
        columnClass = toClassName(sqlColumnName)
        tableTemplateParameters += ',\n               ' + tableNamespace + '::' + columnClass
开发者ID:SuperV1234,项目名称:NetLayer,代码行数:33,代码来源:ddl2cpp.py

示例5: ZeroOrMore

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]
record = (recordA_ ^
          recordSOA_ ^
          recordNS_ ^
          recordMX_ ^
          recordCNAME_ ^
          recordTXT_ ^
          recordSRV_ ^
          recordPTR_ ^
          recordRP_ ^
          recordLOC_ ^
          recordNAPTR_)

lines = (Group(origin | ttl)('DIRECTIVE') |
         comment |
         record)

zoneParser = ZeroOrMore(lines)('zone') + stringEnd

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "Usage: {} <zone_file>".format(sys.argv[0])
        sys.exit(-1)

    zone_file = sys.argv[1]

    try:
        tokens = zoneParser.parseFile(zone_file)
        print tokens.asXML()
    except ParseException:
        raise
开发者ID:atopuzov,项目名称:playground,代码行数:32,代码来源:bind_zone_parser.py

示例6: loadSource

# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import parseFile [as 别名]

#.........这里部分代码省略.........
            data = self.convertParameter( var.value, var.encoding )
        else:
            var.value = Q(float(data))
            data = int(round(float(data)))

        if label in self.defines:
            logger.error( "Error in file '%s': attempted to reassign '%s' to '%s' (from prev. value of '%s') in a var statement." %(self.currentFile, label, data, self.defines[label]) )
            raise ppexception("variable redifinition", self.currentFile, lineno, label)
        else:
            self.defines[label] = label # add the variable to the dictionary of definitions to prevent identifiers and variables from having the same name
                                        # however, we do not want it replaced with a number but keep the name for the last stage of compilation
            pass
        var.data = data
        self.variabledict.update({ label: var})
        if var.type == "exitcode":
            self._exitcodes[data & 0x0000ffff] = var
    
    def command_action( self, text, loc, arg):
        print("command_action", self.currentFile, lineno(loc, text), arg[0:1], arg[1].split(",") if len(arg)>1 else "") 
        
    def label_command_action( self, text, loc, arg):
        print("label_command_action", self.currentFile, lineno(loc, text), arg[0:2], arg[2].split(",") if len(arg)>2 else "") 
     
    def addLabel(self, label, address, sourcename, lineno):
        if label is not None:
            self.labeldict[label] = address

    
    def insert_action( self, text, loc, arg ):
        oldfile = self.currentFile
        print("insert_action", lineno(loc, text), arg)
        myprogram = self.program.copy()
        self.currentFile = arg[0][1:-1]
        result = myprogram.parseFile( self.currentFile )
        self.currentFile = oldfile
        print(result)
        return result
    
    def assembleFile(self, filename):
        self.currentFile = filename
        result = self.program.parseFile( self.currentFile )
        return result

    def setHardware(self, adIndexList, adBoards, timestep ):
        self.adIndexList = adIndexList
        self.adBoards = adBoards
        self.timestep = timestep
        assert self.timestep.has_dimension('s')
        
    def saveSource(self):
        for name, text in self.source.items():
            with open(os.path.join(self.pp_dir, name), 'w') as f:
                f.write(text)            
        
    def loadSource(self, pp_file):
        """ Load the source pp_file
        #include files are loaded recursively
        all code lines are added to self.sourcelines
        for each source file the contents are added to the dictionary self.source
        """
        self.source.clear()
        self.pp_dir, self.pp_filename = os.path.split(pp_file)
        self.sourcelines = []
        self.insertSource(self.pp_filename)
        self.compileCode()
开发者ID:pyIonControl,项目名称:IonControl,代码行数:69,代码来源:PulseProgramBNF.py


注:本文中的pyparsing.ZeroOrMore.parseFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。