Skip to content

Commit 30e4d05

Browse files
committed
Refactor the generator scripts for unicode tables
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
1 parent 92f74f3 commit 30e4d05

File tree

5 files changed

+619
-709
lines changed

5 files changed

+619
-709
lines changed

jerry-core/lit/lit-unicode-conversions.inc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
14-
*
15-
* This file is automatically generated by the unicode_case_conversion.py script. Do not edit!
1614
*/
1715

16+
/* This file is automatically generated by the unicode_case_conversion.py script
17+
* from UnicodeData-9.0.0.txt and SpecialCasing-9.0.0.txt files. Do not edit! */
18+
1819
/* Contains start points of character case ranges (these are bidirectional conversions). */
1920
static const uint16_t jerry_character_case_ranges[] JERRY_CONST_DATA =
2021
{
@@ -154,9 +155,8 @@ static const uint16_t jerry_upper_case_conversions[] JERRY_CONST_DATA =
154155
0x0046, 0x004c
155156
};
156157

157-
/* Number of one-to-one, one-to-two, and one-to-three lowercase conversions. */
158+
/* Number of one-to-one, one-to-two, and one-to-three uppercase conversions. */
158159
static const uint8_t jerry_upper_case_conversion_counters[] JERRY_CONST_DATA =
159160
{
160161
0x001c, 0x002c, 0x0010
161162
};
162-

jerry-core/lit/lit-unicode-ranges.inc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
14-
*
15-
* This file is automatically generated by the unicode_ranges.py script
16-
* from UnicodeData-3.0.0.txt. Do not edit!
1714
*/
1815

16+
/* This file is automatically generated by the unicode_ranges.py script
17+
* from UnicodeData-3.0.0.txt. Do not edit! */
18+
1919
/**
2020
* Character interval starting points for the unicode letters.
2121
*
@@ -180,4 +180,3 @@ static const uint16_t jerry_unicode_separator_chars[] JERRY_CONST_DATA =
180180
{
181181
0x1680, 0x180e, 0x202f, 0x205f, 0x3000
182182
};
183-

tools/unicode_c_source.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright JS Foundation and other contributors, http://js.foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
LICENSE = """/* Copyright JS Foundation and other contributors, http://js.foundation
18+
*
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
*
23+
* http://www.apache.org/licenses/LICENSE-2.0
24+
*
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*/"""
31+
32+
33+
class Source(object):
34+
def __init__(self, filepath):
35+
self.__filepath = filepath
36+
self.__header = [LICENSE, ""]
37+
self.__data = []
38+
39+
def complete_header(self, completion):
40+
self.__header.append(completion)
41+
self.__header.append("") # for an extra empty line
42+
43+
44+
def add_table(self, table, table_name, table_type, table_descr):
45+
self.__data.append(table_descr)
46+
self.__data.append("static const %s jerry_%s[] JERRY_CONST_DATA =" % (table_type, table_name))
47+
self.__data.append("{")
48+
self.__data.append(format_code(table, 1))
49+
self.__data.append("};")
50+
self.__data.append("") # for an extra empty line
51+
52+
53+
54+
def generate(self):
55+
with open(self.__filepath, 'w') as genereted_source:
56+
genereted_source.write("\n".join(self.__header))
57+
genereted_source.write("\n".join(self.__data))
58+
59+
60+
def regroup(list_to_group, num):
61+
return [list_to_group[i:i+num] for i in range(0, len(list_to_group), num)]
62+
63+
64+
def hex_format(char):
65+
if isinstance(char, str):
66+
char = ord(char)
67+
68+
return "0x{:04x}".format(char)
69+
70+
71+
def format_code(code, indent):
72+
lines = []
73+
# convert all characters to hex format
74+
converted_code = [hex_format(char) for char in code]
75+
# 10 hex number per line
76+
for line in regroup(", ".join(converted_code), 10 * 8):
77+
lines.append((' ' * indent) + line.strip())
78+
return "\n".join(lines)

0 commit comments

Comments
 (0)