Python pyparsing.col() Examples
The following are 15
code examples of pyparsing.col().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyparsing
, or try the search function
.
Example #1
Source File: include_preprocessor.py From pyparsing with MIT License | 6 votes |
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
Example #2
Source File: test_astutil.py From gcl with MIT License | 6 votes |
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)
Example #3
Source File: parseTabularData.py From phpsploit with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: parseTabularData.py From pyparsing with MIT License | 5 votes |
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)
Example #5
Source File: test_astutil.py From gcl with MIT License | 5 votes |
def testScopeObjectHasLocation(self): scope = readAndQueryScope('|henk = 5') self.assertEquals(1, scope['henk'].location.lineno) self.assertEquals(1, scope['henk'].location.col)
Example #6
Source File: test_astutil.py From gcl with MIT License | 5 votes |
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)
Example #7
Source File: test_astutil.py From gcl with MIT License | 5 votes |
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)
Example #8
Source File: test_astutil.py From gcl with MIT License | 5 votes |
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)
Example #9
Source File: ast.py From gcl with MIT License | 5 votes |
def col(self): return p.col(self.start_offset, self.string)
Example #10
Source File: ast.py From gcl with MIT License | 5 votes |
def end_col(self): assert self.end_offset is not None return p.col(self.end_offset, self.string)
Example #11
Source File: ast.py From gcl with MIT License | 5 votes |
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)))
Example #12
Source File: ast.py From gcl with MIT License | 5 votes |
def __repr__(self): return 'SourceLocation(%r, %r:%r, %r:%r)' % (self.filename, self.lineno, self.col, self.end_lineno, self.end_col)
Example #13
Source File: ast.py From gcl with MIT License | 5 votes |
def __init__(self, filename, line, col): self.filename = filename self.line = line self.col = col
Example #14
Source File: ast.py From gcl with MIT License | 5 votes |
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)
Example #15
Source File: ast.py From gcl with MIT License | 5 votes |
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)