• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyparsing.col函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyparsing.col函数的典型用法代码示例。如果您正苦于以下问题:Python col函数的具体用法?Python col怎么用?Python col使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _resolve_variable

    def _resolve_variable(config, substitution):
        """
        :param config:
        :param substitution:
        :return: (is_resolved, resolved_variable)
        """
        variable = substitution.variable
        try:
            return True, config.get(variable)
        except ConfigMissingException:
            # default to environment variable
            value = os.environ.get(variable)

            if value is None:
                if substitution.optional:
                    return False, None
                else:
                    raise ConfigSubstitutionException(
                        "Cannot resolve variable ${{{variable}}} (line: {line}, col: {col})".format(
                            variable=variable,
                            line=lineno(substitution.loc, substitution.instring),
                            col=col(substitution.loc, substitution.instring)))
            elif isinstance(value, ConfigList) or isinstance(value, ConfigTree):
                raise ConfigSubstitutionException(
                    "Cannot substitute variable ${{{variable}}} because it does not point to a "
                    "string, int, float, boolean or null {type} (line:{line}, col: {col})".format(
                        variable=variable,
                        type=value.__class__.__name__,
                        line=lineno(substitution.loc, substitution.instring),
                        col=col(substitution.loc, substitution.instring)))
            return True, value
开发者ID:emilybache,项目名称:pyhocon,代码行数:31,代码来源:config_parser.py


示例2: expand_state_definition

def expand_state_definition(source, loc, tokens):
    indent = " " * (col(loc,source)-1)
    statedef = []
    
    # build list of states
    states = set()
    fromTo = {}
    for tn in tokens.transitions:
        states.add(tn.fromState)
        states.add(tn.toState)
        fromTo[tn.fromState] = tn.toState
    
    # define base class for state classes
    baseStateClass = tokens.name + "State"
    statedef.extend([
        "class %s(object):" % baseStateClass,
        "    def __str__(self):",
        "        return self.__class__.__name__",
        "    def next_state(self):",
        "        return self._next_state_class()" ])
    
    # define all state classes
    statedef.extend(
        "class %s(%s): pass" % (s,baseStateClass) 
            for s in states )
    statedef.extend(
        "%s._next_state_class = %s" % (s,fromTo[s]) 
            for s in states if s in fromTo )
           
    return indent + ("\n"+indent).join(statedef)+"\n"
开发者ID:0x0mar,项目名称:phpsploit,代码行数:30,代码来源:stateMachine2.py


示例3: line_col

def line_col(primitive):
    loc = location(primitive)
    src = source(primitive)
    if src and loc:
        return lineno(loc, src), col(loc, src)
    else:
        return None, None
开发者ID:rm-hull,项目名称:yalix,代码行数:7,代码来源:source_view.py


示例4: checkPeerIndent

def checkPeerIndent( s, l, t ):
	c = p.col( l, s )
	print(  c, indentStack[-1] )
	if( c != indentStack[-1] ):
		if( ( not indentStack ) or c > indentStack[-1] ):
			raise p.ParseFatalException( s, l, "illegal nesting" )
		raise p.ParseException( s, l, "not a peer entry" )
开发者ID:streed,项目名称:simplePB,代码行数:7,代码来源:grammar.py


示例5: getMessage

			def getMessage(pstr, pos, filepath=''):
				line = pyparsing.line(pos, pstr);
				lineno = pyparsing.lineno(pos, pstr);
				col = pyparsing.col(pos, pstr)
				arrow = ( '-'  * (col-1) + '^');
				ls = os.linesep + '    ';
				return '  in file {filepath} (line: {lineno}, col: {col}){ls}{line}{ls}{arrow}'.format(**locals());
开发者ID:cpriest,项目名称:BanBot,代码行数:7,代码来源:Rule.py


示例6: check_sub_indent

 def check_sub_indent(string, location, tokens):
     """Check the indentation."""
     cur_col = col(location, string)
     if cur_col > indent_stack[-1]:
         indent_stack.append(cur_col)
     else:
         raise ParseException(string, location, "not a subentry")
开发者ID:SCOAP3,项目名称:invenio,代码行数:7,代码来源:parser.py


示例7: resolve_substitutions

    def resolve_substitutions(config):
        ConfigParser._fixup_self_references(config)
        substitutions = ConfigParser._find_substitutions(config)
        if len(substitutions) > 0:
            unresolved = True
            any_unresolved = True
            _substitutions = []
            while any_unresolved and len(substitutions) > 0 and set(substitutions) != set(_substitutions):
                unresolved = False
                any_unresolved = True
                _substitutions = substitutions[:]

                for substitution in _substitutions:
                    is_optional_resolved, resolved_value = ConfigParser._resolve_variable(config, substitution)

                    # if the substitution is optional
                    if not is_optional_resolved and substitution.optional:
                        resolved_value = None

                    unresolved, new_substitutions, result = ConfigParser._do_substitute(substitution, resolved_value, is_optional_resolved)
                    any_unresolved = unresolved or any_unresolved
                    substitutions.extend(new_substitutions)
                    if not isinstance(result, ConfigValues):
                        substitutions.remove(substitution)

            ConfigParser._final_fixup(config)
            if unresolved:
                raise ConfigSubstitutionException("Cannot resolve {variables}. Check for cycles.".format(
                    variables=', '.join('${{{variable}}}: (line: {line}, col: {col})'.format(
                        variable=substitution.variable,
                        line=lineno(substitution.loc, substitution.instring),
                        col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))

        return config
开发者ID:cnspica,项目名称:pyhocon,代码行数:34,代码来源:config_parser.py


示例8: check_unindent

 def check_unindent(string, location, tokens):
     """Check the 'undentation'."""
     if location >= len(string):
         return
     cur_col = col(location, string)
     if not(cur_col < indent_stack[-1] and cur_col <= indent_stack[-2]):
         raise ParseException(string, location, "not an unindent")
开发者ID:SCOAP3,项目名称:invenio,代码行数:7,代码来源:parser.py


示例9: transform

    def transform(self):
        def determine_type(token):
            return ConfigTree if isinstance(token, ConfigTree) else ConfigList if isinstance(token, list) else str

        def format_str(v):
            return "" if v is None else str(v)

        if self.has_substitution():
            return self

        # remove None tokens
        tokens = [token for token in self.tokens if token is not None]

        if not tokens:
            return None

        # check if all tokens are compatible
        first_tok_type = determine_type(tokens[0])
        for index, token in enumerate(tokens[1:]):
            tok_type = determine_type(token)
            if first_tok_type is not tok_type:
                raise ConfigWrongTypeException(
                    "Token '{token}' of type {tok_type} (index {index}) must be of type {req_tok_type} (line: {line}, col: {col})".format(
                        token=token,
                        index=index + 1,
                        tok_type=tok_type.__name__,
                        req_tok_type=first_tok_type.__name__,
                        line=lineno(self._loc, self._instring),
                        col=col(self._loc, self._instring),
                    )
                )

        if first_tok_type is ConfigTree:
            result = ConfigTree()
            for token in tokens:
                for key, val in token.items():
                    # update references for substituted contents
                    if isinstance(val, ConfigValues):
                        val.parent = result
                        val.key = key
                    result[key] = val
            return result
        elif first_tok_type is ConfigList:
            result = []
            main_index = 0
            for sublist in tokens:
                sublist_result = ConfigList()
                for token in sublist:
                    if isinstance(token, ConfigValues):
                        token.parent = result
                        token.key = main_index
                    main_index += 1
                    sublist_result.append(token)
                result.extend(sublist_result)
            return [result]
        else:
            if len(tokens) == 1:
                return tokens[0]
            else:
                return "".join(format_str(token) for token in tokens[:-1]) + format_str(tokens[-1])
开发者ID:pombredanne,项目名称:pyhocon,代码行数:60,代码来源:config_tree.py


示例10: check_unindent

 def check_unindent(self, s, l, t):
     if l >= len(s):
         return
     curCol = col(l, s)
     if not(curCol < self.indentStack[-1]
            and curCol <= self.indentStack[-2]):
         raise ParseException(s, l, "not an unindent")
开发者ID:PoundPay,项目名称:pabl,代码行数:7,代码来源:parser.py


示例11: __init__

 def __init__(self, st, locn, tokString):
     self.token_string = tokString
     self.loc = locn
     self.before_line = line(locn - 1, st)
     self.source_line = line(locn, st)
     self.line_num = lineno(locn, st)
     self.col = col(locn, st)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:7,代码来源:__init__.py


示例12: _parse_action_obj

 def _parse_action_obj(self, source, idx, tokin):
     value = tokin[0].asDict()
     return [{'type': 'obj',
              'line': pp.lineno(idx, source),
              'col': pp.col(idx, source),
              'id_type': value.get('id_type'),
              'id_fixed': value.get('id_fixed'),
              'key': (value.get('class'), value.get('id_fixed', 'xxx'))}]
开发者ID:Datera,项目名称:rtslib,代码行数:8,代码来源:config_parser.py


示例13: checkUnindent

def checkUnindent( s, l, t ):
	if( l >= len( s ) ):
		return

	c = p.col( l, s )

	if( not (  c < indentStack[-1] and c <= indentStack[-2] ) ):
		raise p.ParseException( s, l, "not an unindent" )
开发者ID:streed,项目名称:simplePB,代码行数:8,代码来源:grammar.py


示例14: transform

    def transform(self):
        def determine_type(token):
            return ConfigTree if isinstance(token, ConfigTree) else ConfigList if isinstance(token, list) else str

        def format_str(v, last=False):
            if isinstance(v, ConfigQuotedString):
                return v.value + ('' if last else v.ws)
            else:
                return '' if v is None else str(v)

        if self.has_substitution():
            return self

        # remove None tokens
        tokens = [token for token in self.tokens if token is not None]

        if not tokens:
            return None

        # check if all tokens are compatible
        first_tok_type = determine_type(tokens[0])
        for index, token in enumerate(tokens[1:]):
            tok_type = determine_type(token)
            if first_tok_type is not tok_type:
                raise ConfigWrongTypeException(
                    "Token '{token}' of type {tok_type} (index {index}) must be of type {req_tok_type} (line: {line}, col: {col})".format(
                        token=token,
                        index=index + 1,
                        tok_type=tok_type.__name__,
                        req_tok_type=first_tok_type.__name__,
                        line=lineno(self._loc, self._instring),
                        col=col(self._loc, self._instring)))

        if first_tok_type is ConfigTree:
            result = ConfigTree()
            for token in tokens:
                ConfigTree.merge_configs(result, token, copy_trees=True)
            return result
        elif first_tok_type is ConfigList:
            result = []
            main_index = 0
            for sublist in tokens:
                sublist_result = ConfigList()
                for token in sublist:
                    if isinstance(token, ConfigValues):
                        token.parent = result
                        token.key = main_index
                    main_index += 1
                    sublist_result.append(token)
                result.extend(sublist_result)
            return result
        else:
            if len(tokens) == 1:
                if isinstance(tokens[0], ConfigQuotedString):
                    return tokens[0].value
                return tokens[0]
            else:
                return ''.join(format_str(token) for token in tokens[:-1]) + format_str(tokens[-1], True)
开发者ID:ryban,项目名称:pyhocon,代码行数:58,代码来源:config_tree.py


示例15: _parse_action_attr

 def _parse_action_attr(self, source, idx, tokin):
     value = tokin[0]
     tokout = {'type': 'attr',
               'line': pp.lineno(idx, source),
               'col': pp.col(idx, source),
               'key': (value[0], value[1])}
     if len(value) > 2:
         tokout['comment'] = value[2][1:].strip()
     return [tokout]
开发者ID:Datera,项目名称:rtslib,代码行数:9,代码来源:config_parser.py


示例16: action

 def action(s, loc, token):
     _lineno = lineno(loc, s)
     _colno = col(loc, s) - 1
     logger.info("log={0} (lineno={1}, col={2})".format(loc, _lineno, _colno))
     logger.debug("comment: {0}".format(token[0]))
     logger.debug("comment: {0}".format(nodeInfo(token)))
     _comment = ast.Comment(token[0][2:])
     _comment.loc_info = (_lineno, _colno)
     return _comment
开发者ID:jtfrom9,项目名称:yarl,代码行数:9,代码来源:parser.py


示例17: resolve_substitutions

    def resolve_substitutions(cls, config, accept_unresolved=False):
        has_unresolved = False
        cls._fixup_self_references(config, accept_unresolved)
        substitutions = cls._find_substitutions(config)
        if len(substitutions) > 0:
            unresolved = True
            any_unresolved = True
            _substitutions = []
            cache = {}
            while any_unresolved and len(substitutions) > 0 and set(substitutions) != set(_substitutions):
                unresolved = False
                any_unresolved = True
                _substitutions = substitutions[:]

                for substitution in _substitutions:
                    is_optional_resolved, resolved_value = cls._resolve_variable(config, substitution)

                    # if the substitution is optional
                    if not is_optional_resolved and substitution.optional:
                        resolved_value = None
                    if isinstance(resolved_value, ConfigValues):
                        parents = cache.get(resolved_value)
                        if parents is None:
                            parents = []
                            link = resolved_value
                            while isinstance(link, ConfigValues):
                                parents.append(link)
                                link = link.overriden_value
                            cache[resolved_value] = parents

                    if isinstance(resolved_value, ConfigValues) \
                       and substitution.parent in parents \
                       and hasattr(substitution.parent, 'overriden_value') \
                       and substitution.parent.overriden_value:

                        # self resolution, backtrack
                        resolved_value = substitution.parent.overriden_value

                    unresolved, new_substitutions, result = cls._do_substitute(substitution, resolved_value, is_optional_resolved)
                    any_unresolved = unresolved or any_unresolved
                    substitutions.extend(new_substitutions)
                    if not isinstance(result, ConfigValues):
                        substitutions.remove(substitution)

            cls._final_fixup(config)
            if unresolved:
                has_unresolved = True
                if not accept_unresolved:
                    raise ConfigSubstitutionException("Cannot resolve {variables}. Check for cycles.".format(
                        variables=', '.join('${{{variable}}}: (line: {line}, col: {col})'.format(
                            variable=substitution.variable,
                            line=lineno(substitution.loc, substitution.instring),
                            col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))

        cls._final_fixup(config)
        return has_unresolved
开发者ID:chimpler,项目名称:pyhocon,代码行数:56,代码来源:config_parser.py


示例18: __str__

 def __str__(self):
     #TODO: create error message which is understood by Pydev. Format:
     #File "/home/eike/codedir/freeode/trunk/freeode_py/simlparser.py", line 956, in createProcess
     if self.str == None:
         return 'Error! ' + self.message + '\n At position: ' + str(self.loc)
     else:
         lineno = pyparsing.lineno(self.loc, self.str)
         col = pyparsing.col(self.loc, self.str)
         return 'Error! %s \n' % self.message +\
                'Line: %d, Column: %d' % (lineno, col)
开发者ID:BackupTheBerlios,项目名称:freeode-svn,代码行数:10,代码来源:ast.py


示例19: start_action

 def start_action(self, instring, loc, expr):
     self.writer.startElement(
         u"attempt",
         attributes={
             u"class": unicode(expr.__class__.__name__),
             u"loc": unicode(repr(loc)),
             u"expr": unicode(repr(expr)),
             u"lineno": unicode(lineno(loc, instring)),
             u"col": unicode(col(loc, instring)),
         },
     )
开发者ID:jbofill,项目名称:rdflib,代码行数:11,代码来源:parser.py


示例20: __init__

 def __init__(self, message, print_location=True):
     super(SemanticException, self).__init__()
     self._message = message
     self.location = exshared.location
     self.print_location = print_location
     if exshared.location is not None:
         self.line = lineno(exshared.location, exshared.text)
         self.col = col(exshared.location, exshared.text)
         self.text = line(exshared.location, exshared.text)
     else:
         self.line = self.col = self.text = None
开发者ID:fablab-ka,项目名称:OpenSCAD2D,代码行数:11,代码来源:cadfileparser.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python optimizer.OptValue类代码示例发布时间:2022-05-27
下一篇:
Python pypar.size函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap