本文整理汇总了Python中pyparsing.lineno函数的典型用法代码示例。如果您正苦于以下问题:Python lineno函数的具体用法?Python lineno怎么用?Python lineno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lineno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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
示例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
示例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)
示例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
示例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
示例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());
示例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
示例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])
示例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)
示例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'))}]
示例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)
示例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
示例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]