本文整理汇总了Python中pyparsing.col方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.col方法的具体用法?Python pyparsing.col怎么用?Python pyparsing.col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing
的用法示例。
在下文中一共展示了pyparsing.col方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_include_contents
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def read_include_contents(s, l, t):
include_file_ref = t.include_file_name
include_echo = "/* {} */".format(pp.line(l, s).strip())
# guard against recursive includes
if include_file_ref not in seen:
seen.add(include_file_ref)
included_file_contents = Path(include_file_ref).read_text()
return (
include_echo
+ "\n"
+ include_directive.transformString(included_file_contents)
)
else:
lead = " " * (pp.col(l, s) - 1)
return "/* recursive include! */\n{}{}".format(lead, include_echo)
# attach include processing method as parse action (parse-time callback)
# to include_directive expression
示例2: testCompletePastIncludesWhenFileChangesAndCachingDisabled
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def testCompletePastIncludesWhenFileChangesAndCachingDisabled(self):
includable = ["before = 1;"]
def load_from_var(base, rel, env=None):
return gcl.loads(includable[0], env=env)
source = """
inc = include 'inc.gcl';
bar = inc.|
""".strip()
source, line, col = find_cursor(source)
tree = gcl.reads(source, filename='input.gcl', allow_errors=True, loader=load_from_var)
with framework.DisableCaching():
completions = ast_util.find_completions_at_cursor(tree, 'input.gcl', line, col)
self.assertTrue('before' in completions)
includable[0] = "after = 2;"
with framework.DisableCaching():
completions = ast_util.find_completions_at_cursor(tree, 'input.gcl', line, col)
self.assertTrue('after' in completions)
示例3: mustMatchCols
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def mustMatchCols(startloc,endloc):
return lambda s,l,t: startloc <= col(l,s) <= endloc
# helper to define values in a space-delimited table
# (change empty_cell_is_zero to True if a value of 0 is desired for empty cells)
示例4: mustMatchCols
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def mustMatchCols(startloc, endloc):
return lambda s, l, t: startloc <= col(l, s) <= endloc
# helper to define values in a space-delimited table
# (change empty_cell_is_zero to True if a value of 0 is desired for empty cells)
示例5: testScopeObjectHasLocation
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def testScopeObjectHasLocation(self):
scope = readAndQueryScope('|henk = 5')
self.assertEquals(1, scope['henk'].location.lineno)
self.assertEquals(1, scope['henk'].location.col)
示例6: readAndQueryScope
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def readAndQueryScope(source, **kwargs):
source, line, col = find_cursor(source)
tree = gcl.reads(source, filename='input.gcl', **kwargs)
rootpath = tree.find_tokens(gcl.SourceQuery('input.gcl', line, col))
return ast_util.enumerate_scope(rootpath)
示例7: readAndAutocomplete
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def readAndAutocomplete(source, root_env=gcl.Environment({})):
source, line, col = find_cursor(source)
tree = gcl.reads(source, filename='input.gcl', allow_errors=True)
return ast_util.find_completions_at_cursor(tree, 'input.gcl', line, col, root_env=root_env)
示例8: readAndFindValue
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def readAndFindValue(source):
source, line, col = find_cursor(source)
tree = gcl.reads(source, filename='input.gcl', allow_errors=True)
return ast_util.find_value_at_cursor(tree, 'input.gcl', line, col)
示例9: col
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def col(self):
return p.col(self.start_offset, self.string)
示例10: end_col
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def end_col(self):
assert self.end_offset is not None
return p.col(self.end_offset, self.string)
示例11: contains
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def contains(self, q):
return (q.filename == self.filename
and (q.line > self.lineno or (q.line == self.lineno and q.col >= self.col))
and (q.line < self.end_lineno or (q.line == self.end_lineno and q.col < self.end_col)))
示例12: __repr__
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def __repr__(self):
return 'SourceLocation(%r, %r:%r, %r:%r)' % (self.filename, self.lineno, self.col, self.end_lineno, self.end_col)
示例13: __init__
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def __init__(self, filename, line, col):
self.filename = filename
self.line = line
self.col = col
示例14: find_offset
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def find_offset(s, line, col):
c_line = 1
c_col = 1
for i in range(len(s)):
if (c_line == line and c_col >= col) or c_line > line:
return i
if s[i] == '\n':
c_col = 1
c_line += 1
else:
c_col += 1
return len(s)
示例15: reads
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import col [as 别名]
def reads(s, filename, loader, implicit_tuple, allow_errors):
"""Load but don't evaluate a GCL expression from a string."""
try:
the_context.filename = filename
the_context.loader = loader
grammar = make_grammar(allow_errors=allow_errors)
root = grammar.start_tuple if implicit_tuple else grammar.start
return root.parseWithTabs().parseString(s, parseAll=True)[0]
except (p.ParseException, p.ParseSyntaxException) as e:
loc = SourceLocation(s, find_offset(s, e.lineno, e.col))
raise exceptions.ParseError(the_context.filename, loc, e.msg)