GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — More gracefully degrading string formatting syntax translation · rusthon/java2python@3be8010

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java2python/mod
    • transform.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java2python/mod/transform.py‎

Copy file name to clipboardExpand all lines: java2python/mod/transform.py
+14-4Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,25 @@ def formatString(node, config):
117117
method = dot.parent
118118
arg_list = method.firstChildOfType(tokens.ARGUMENT_LIST)
119119
call_args = [arg for arg in arg_list.childrenOfType(tokens.EXPR)]
120-
121-
format = call_args[0].firstChildOfType(tokens.STRING_LITERAL)
122120
args = [arg.firstChildOfType(tokens.IDENT) for arg in call_args[1:]]
123121

124-
# Translate format syntax
125-
format.token.text = re.sub(r'%(?P<idx>\d+\$)?(?P<convers>[scdoxefg])',
122+
# Translate format syntax (if format == string_literal)
123+
format = call_args[0].firstChildOfType(tokens.STRING_LITERAL)
124+
if format:
125+
format.token.text = \
126+
re.sub(r'%(?P<idx>\d+\$)?(?P<convers>[scdoxefg])',
126127
formatSyntaxTransf,
127128
format.token.text,
128129
flags=re.IGNORECASE)
130+
else:
131+
# Translation should happen at runtime
132+
format = call_args[0].firstChild()
133+
if format.type == tokens.IDENT:
134+
# String variable
135+
pass
136+
else:
137+
# Function that returns String
138+
pass
129139

130140
left_ident = dot.children[0]
131141
right_ident = dot.children[1]

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.