diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-02 20:52:40 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-02 20:52:40 +0200 |
commit | 05abbac297d3fe97d159b8468fb463d6e7a28c2b (patch) | |
tree | f1d69c6376c63ebc4077b80acb4a67eaa0b375ad /tests | |
parent | 237c37e71995965b49b717cd43cba932ba0e654f (diff) | |
download | weechat-05abbac297d3fe97d159b8468fb463d6e7a28c2b.zip |
tests: add subscript in script generator
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/scripts/python/unparse.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/scripts/python/unparse.py b/tests/scripts/python/unparse.py index 42b4a74e7..f3c1066b7 100755 --- a/tests/scripts/python/unparse.py +++ b/tests/scripts/python/unparse.py @@ -289,6 +289,15 @@ class UnparsePython(object): # note: deprecated since Python 3.8, replaced by ast.Constant self.add(repr(node.s)) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + node.value, + '[', + node.slice, + ']', + ) + def _ast_tuple(self, node): """Add an AST Tuple in output.""" self.add( @@ -484,6 +493,17 @@ class UnparsePerl(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$').replace('@', '\\@')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + (self.prefix, '$'), + node.value, + (self.prefix, None), + '->{', + node.slice, + '}', + ) + class UnparseRuby(UnparsePython): """ @@ -821,6 +841,18 @@ class UnparseTcl(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '[dict get ', + (self.prefix, '$'), + node.value, + (self.prefix, None), + ' ', + node.slice, + ']', + ) + class UnparseGuile(UnparsePython): """ @@ -1007,6 +1039,16 @@ class UnparseGuile(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '(assoc-ref ', + node.value, + ' ', + node.slice, + ')', + ) + class UnparseJavascript(UnparsePython): """ @@ -1222,6 +1264,16 @@ class UnparsePhp(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '$', + node.value, + '[', + node.slice, + ']', + ) + def get_languages(): """Return a list of supported languages: ['python', 'perl', ...].""" |