本文整理汇总了Python中pyparsing.lineno函数的典型用法代码示例。如果您正苦于以下问题:Python lineno函数的具体用法?Python lineno怎么用?Python lineno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lineno函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: store_vector
def store_vector(self,s,l,t):
q=t.asList()
self.strg=s
self.loc=l
name=q[0]
arg=q[1:]
if self.caseless:
name=name.lower()
if self.templ is None:
argt=self.guess_vectype(arg)
else:
k=self.path[-1].findkw(name)
if k is None:
print "Unknown keyword '%s', line: %d" % (name,
lineno(self.loc,self.strg))
if strict:
sys.exit(1)
argt=None
else:
if k.nargs == -1:
pass
elif len(arg) != k.nargs:
print "Invalid number of elements for key '%s',\
line: %d" % ( name, lineno(self.loc,self.strg))
print " -> %d required, %d given." % (k.nargs, len(arg))
if strict:
sys.exit(1)
argt=self.check_vectype(arg,k.type)
k=Keyword(name,argt,arg)
self.cur.add_kwkw(k,set=True)
开发者ID:juselius,项目名称:gimic,代码行数:30,代码来源:getkw.py
示例2: _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
示例3: check_type
def check_type(self, arg, argt):
print "You hit a bug! Yipeee!"
sys.exit(1)
if (isinstance(arg, tuple) or isinstance(arg, list)):
argt=re.sub('_ARRAY', '', argt)
for i in arg:
self.check_type(i, argt)
if argt == 'INT':
if not ival.match(arg):
print 'Invalid type on line %d: Not an int: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt == 'DBL':
if not dval.match(arg):
print 'Invalid type on line %d: Not a float: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt == 'BOOL':
if not lval.match(arg):
print 'Invalid type on line %d: Not a bool: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt != 'STR':
print 'Invalid type on line %d: Not a %s: \n -> %s' % (
lineno(self.loc,self.strg), argt, line(self.loc,
self.strg).strip())
sys.exit(1)
return argt
开发者ID:juselius,项目名称:libgetkw,代码行数:32,代码来源:getkw.py
示例4: check_type
def check_type(self, arg, argt):
if argt == 'INT':
if not ival.match(arg):
print 'Invalid type on line %d: Not an int: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt == 'DBL':
if not dval.match(arg):
print 'Invalid type on line %d: Not a float: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt == 'BOOL':
if not lval.match(arg):
print 'Invalid type on line %d: Not a bool: \n -> %s' % (
lineno(self.loc,self.strg), line(self.loc,
self.strg).strip())
sys.exit(1)
elif argt != 'STR':
print 'Invalid type on line %d: Not a %s: \n -> %s' % (
lineno(self.loc,self.strg), argt, line(self.loc,
self.strg).strip())
sys.exit(1)
return argt
开发者ID:juselius,项目名称:gimic,代码行数:25,代码来源:getkw.py
示例5: __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
示例6: 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
示例7: __init__
def __init__(self, s, loc, toks):
self.cmd = str(toks[0])[1:]
#print 'cmd', self.cmd
self.args = toks[1].asList()
self.params = toks[2].asList()
self.lineno = lineno(loc, s)
self.filename = None
开发者ID:Avatarchik,项目名称:EmguCV-Unity,代码行数:7,代码来源:latexparser.py
示例8: 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
示例9: 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
示例10: 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
示例11: set_line_number
def set_line_number(string, location, tokens):
if len(tokens) == 1:
line_number = lineno(location, string)
tokens_cache[tokens[0]] = line_number
tokens.line_number = line_number
else:
for item in tokens:
tokens.line_number = tokens_cache.get(item)
开发者ID:heartshare,项目名称:nginx-amplify-agent,代码行数:8,代码来源:parser.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: 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
示例14: insert_action
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
开发者ID:pyIonControl,项目名称:IonControl,代码行数:9,代码来源:PulseProgramBNF.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: push_sect
def push_sect(self,k):
self.stack.append(k)
self.cur=self.stack[-1]
if self.templ is not None:
x=self.path[-1].findsect(k.name)
if x is None:
print "Invalid section on line %d: \n%s" % (
lineno(self.loc,self.strg), line(self.loc,self.strg))
sys.exit(1)
self.path.append(x)
开发者ID:juselius,项目名称:gimic,代码行数:10,代码来源:getkw.py
示例19: __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
示例20: 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
注:本文中的pyparsing.lineno函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论