diff options
| author | yum <yum.food.vr@gmail.com> | 2023-01-01 21:05:27 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-01-01 21:44:45 -0800 |
| commit | e25bdba3a3a53b09be5269d8b065c13b73ab55c3 (patch) | |
| tree | 1d1dc1d94cde92c2f4f8ce86017395054787515d /Python/Dependencies/future-0.18.2/docs/other/find_pattern.py | |
| parent | 0d408cc812a094a708edbe4baf536e928731cfc3 (diff) | |
Embed git in package
package.ps1 fetches PortableGit and embeds it in the package. This
eliminates all but one runtime dependency (MSVC++ Redistributable).
* Move Python into a new FOSS folder.
Diffstat (limited to 'Python/Dependencies/future-0.18.2/docs/other/find_pattern.py')
| -rw-r--r-- | Python/Dependencies/future-0.18.2/docs/other/find_pattern.py | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/Python/Dependencies/future-0.18.2/docs/other/find_pattern.py b/Python/Dependencies/future-0.18.2/docs/other/find_pattern.py deleted file mode 100644 index 1a5da35..0000000 --- a/Python/Dependencies/future-0.18.2/docs/other/find_pattern.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python - -"""Script that makes determining PATTERN for a new [2to3] fix much easier. - -Figuring out exactly what PATTERN I want for a given fixer class is -getting tedious. This script will step through each possible subtree -for a given string, allowing you to select which one you want. It will -then try to figure out an appropriate pattern to match that tree. This -pattern will require some editing (it will be overly restrictive) but -should provide a solid base to work with and handle the tricky parts. - -Usage: - - python find_pattern.py "g.throw(E, V, T)" - -This will step through each subtree in the parse. To reject a -candidate subtree, hit enter; to accept a candidate, hit "y" and -enter. The pattern will be spit out to stdout. - -For example, the above will yield a succession of possible snippets, -skipping all leaf-only trees. I accept - -'g.throw(E, V, T)' - -This causes find_pattern to spit out - -power< 'g' trailer< '.' 'throw' > - trailer< '(' arglist< 'E' ',' 'V' ',' 'T' > ')' > > - - -Some minor tweaks later, I'm left with - -power< any trailer< '.' 'throw' > - trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' > > - -which is exactly what I was after. - -Larger snippets can be placed in a file (as opposed to a command-line -arg) and processed with the -f option. -""" -from __future__ import print_function - -__author__ = "Collin Winter <collinw@gmail.com>" - -# Python imports -import optparse -import sys -from StringIO import StringIO - -# Local imports -from lib2to3 import pytree -from lib2to3.pgen2 import driver -from lib2to3.pygram import python_symbols, python_grammar - -driver = driver.Driver(python_grammar, convert=pytree.convert) - -def main(args): - parser = optparse.OptionParser(usage="find_pattern.py [options] [string]") - parser.add_option("-f", "--file", action="store", - help="Read a code snippet from the specified file") - - # Parse command line arguments - options, args = parser.parse_args(args) - if options.file: - tree = driver.parse_file(options.file) - elif len(args) > 1: - tree = driver.parse_stream(StringIO(args[1] + "\n")) - else: - print("You must specify an input file or an input string", file=sys.stderr) - return 1 - - examine_tree(tree) - return 0 - -def examine_tree(tree): - for node in tree.post_order(): - if isinstance(node, pytree.Leaf): - continue - print(repr(str(node))) - verdict = raw_input() - if verdict.strip(): - print(find_pattern(node)) - return - -def find_pattern(node): - if isinstance(node, pytree.Leaf): - return repr(node.value) - - return find_symbol(node.type) + \ - "< " + " ".join(find_pattern(n) for n in node.children) + " >" - -def find_symbol(sym): - for n, v in python_symbols.__dict__.items(): - if v == sym: - return n - -if __name__ == "__main__": - sys.exit(main(sys.argv)) |
