Skip to content

Commit

Permalink
refactor: remove python_indent
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneyJackson committed Apr 17, 2024
1 parent ffe2599 commit 4d9bf3a
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/plcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class {base}({ext}): #{base}:class#
""".format(cls=cls,
base=base,
ext=ext,
cases='\n'.join(python_indent(3,caseList))
cases='\n'.join(indent(3,caseList))
)
return stubString

Expand Down Expand Up @@ -798,9 +798,9 @@ def makeStub(cls):
lhs=lhs,
ext=ext,
ruleString=ruleString,
decls='\n'.join(python_indent(1,decls)),
decls='\n'.join(indent(1,decls)),
params=', '.join(params),
inits='\n'.join(python_indent(2,inits)),
inits='\n'.join(indent(2,inits)),
parse=parseString)
return stubString

Expand Down Expand Up @@ -859,9 +859,9 @@ def __init__({params}):
lhs=lhs,
ext=ext,
ruleString=ruleString,
decls='\n'.join(python_indent(1,decls)),
decls='\n'.join(indent(1,decls)),
params=', '.join(params),
inits='\n'.join(python_indent(2,inits)),
inits='\n'.join(indent(2,inits)),
parse=parseString)
return stubString

Expand All @@ -874,15 +874,6 @@ def indent(n, iList):
# print('### str={}'.format(str))
return newList

def python_indent(n, iList):
### make a new list with the old list items prepended with 4*n spaces
indentString = '\t'*n
newList = []
for item in iList:
newList.append('{}{}'.format(indentString, item))
# print('### str={}'.format(str))
return newList

def makeParse(cls, rhs):
args = []
parseList = []
Expand Down Expand Up @@ -1186,9 +1177,9 @@ def python_sem(nxt):
mod = mod.strip() # mod might be 'import', 'top', etc.
if cls in python_stubs:
if mod and mod != 'ignore' and mod != 'top':
codeString = '\n'.join(python_indent(2,codeString,))
codeString = '\n'.join(indent(2,codeString))
else:
codeString = '\n'.join(python_indent(1,codeString,))
codeString = '\n'.join(indent(1,codeString))
else:
codeString = '\n'.join(codeString)
if mod:
Expand All @@ -1215,7 +1206,7 @@ def python_sem(nxt):
stub = stub.replace(repl, '{} {}'.format(codeString,repl))
else: # the default
repl = '#{}#'.format(cls)
stub = stub.replace(repl, '{}\n\n{}'.format(codeString,python_indent(1,[repl])[0]))
stub = stub.replace(repl, '{}\n\n{}'.format(codeString,indent(1,[repl])[0]))
debug('class {}:\n{}\n'.format(cls, stub))
python_stubs[cls] = stub
else:
Expand Down

0 comments on commit 4d9bf3a

Please sign in to comment.