1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-24 11:56:38 +02:00

tests: add subscript in script generator

This commit is contained in:
Sébastien Helleu
2022-08-02 20:52:40 +02:00
parent 237c37e719
commit 05abbac297
+52
View File
@@ -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', ...]."""