Skip to content

Conversation

@robertsipka
Copy link
Contributor

Extract the source code generator methods into a separated unicode_c_source.py script.
Fix the generator scripts to make them compatible with both Python2 and Python3.
Remove pylint warnings.

@LaszloLango LaszloLango added the tools Related to the tooling scripts label Feb 27, 2017
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

self.__data = ""

def complete_header(self, completion):
header = self.__header[:len(self.__header) - 3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are removing the last three characters always, why don't we leave out from the string in the first place? Or even better do we need to remove those characters at all? can't we just append the completion as a comment and leave the license string alone?

def complete_header(self, completion):
header = self.__header[:len(self.__header) - 3]
header += " *\n" + completion
header += " */\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'm not really fond of adding strings together. I would use a list add any required lines then join them together with \n-s

def add_table(self, table, table_name, table_type, table_descr):
self.__data += (table_descr + "\n"
"static const " + table_type + " jerry_" + table_name + "[] JERRY_CONST_DATA =\n"
"{\n" + format_code(table, 1) + "\n};\n\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the __data is a list then this could look like this:

self.__data.append(table_descr)
self.__data.append("static const %s jerry_%s[] JERRY_CONST_DATA" % (table_type, table_name))
self.__data.append("{")
self.__data.append(format_code(table, 1))
self.__data.append("}")
self.__data.append("") # for an extra empty line

then when writing out the data we can just simple join them together. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galpeter : I like it, thanks! It's a prettier solution and I've changed these parts based on your suggestions.

@robertsipka robertsipka force-pushed the refactor_unicode_scripts branch from 9c41d0f to 38f0e06 Compare March 2, 2017 13:47
class Source(object):
def __init__(self, filepath):
self.__filepath = filepath
self.__header = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I you are creating the list here, why not put the license and the empty line in it by default?

spec_casing_file = os.path.basename(script_args.special_casing)

header_completion = []
header_completion.append("/* This file is automatically generated by the %s script" % os.path.basename(__file__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call append, directly put the strings into the list above.

conv_length = lengths[idx]
# Remove all founded case mapping from the conversion tables after the scanning method
idx = 0
while idx != len(start_points):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... what if we do something like this:

for idx in range(len(start_points)):
    ...

?

@robertsipka robertsipka force-pushed the refactor_unicode_scripts branch from 38f0e06 to 30e4d05 Compare March 7, 2017 10:35
@robertsipka
Copy link
Contributor Author

@galpeter : thanks for your suggestions, I've updated the patch.

self.__data.append("") # for an extra empty line



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many empty lines? Just have one empty line between methods inside a class

try:
result += unichr(int(unicode_char, 16))
except NameError:
result += chr(int(unicode_char, 16))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, but: maybe we should extract the int call before the try-catch. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it accordingly.

Extract the source code generator methods into a separated `unicode_c_source.py` script.
Fix the generator scripts to make them compatible with both Python2 and Python3.
Remove pylint warnings.

JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
@robertsipka robertsipka force-pushed the refactor_unicode_scripts branch from 60c53c2 to 5ef1f3a Compare March 14, 2017 14:25
@galpeter
Copy link
Contributor

lgtm

@LaszloLango LaszloLango merged commit d77d4ae into jerryscript-project:master Mar 16, 2017
@robertsipka robertsipka deleted the refactor_unicode_scripts branch March 16, 2017 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Related to the tooling scripts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants