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


Python pyparsing.col函数代码示例

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


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


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