Add --prettify option, to reformat a script (losing comments).

Since our syntax extensions transform the source at parse time, all syntax extensions are disabled. The optimizations are disabled too, as it doesn't make sense to prettify and optimize at the same time (the optimizer would remove the constants that we're trying to keep).

Addresses #4 in a more user-friendly way.
This commit is contained in:
Sei Lisa 2017-11-19 19:48:35 +01:00
parent e42479756b
commit f492d3e291
2 changed files with 24 additions and 1 deletions

View file

@ -2628,6 +2628,9 @@ list lazy_list_set(list L, integer i, list v)
# # Allow referencing undefined functions inside function definitions.
# self.allowundeffn = 'allowundeffn' in options
# Prettify a source file
self.prettify = 'prettify' in options
# Symbol table:
# This is a list of all local and global symbol tables.
# The first element (0) is the global scope. Each symbol table is a
@ -2650,6 +2653,16 @@ list lazy_list_set(list L, integer i, list v)
self.symtab[0][-1] = None
self.scopeindex = 0
if self.prettify:
# Add the constants as symbol table variables...
for i in self.constants:
self.symtab[0][i] = {'Kind':'v', 'Scope':0,
'Type':lslcommon.PythonType2LSL[type(self.constants[i])]}
# ... and remove them as constants.
self.constants = {}
# Remove TRUE and FALSE from keywords
self.keywords -= set(('TRUE', 'FALSE'))
# Last preprocessor __FILE__. <stdin> means the current file.
self.lastFILE = '<stdin>'