Debian Codegraph @

gen_chartable.py

raw symbols SCIP
1 #!/usr/bin/env python
2 u"""
3 ========================================
4 Character table generator for rjsmin.c
5 ========================================
6
7 Character table generator for rjsmin.c
8
9 :Copyright:
10
11 Copyright 2011 - 2025
12 Andr\xe9 Malo or his licensors, as applicable
13
14 :License:
15
16 Licensed under the Apache License, Version 2.0 (the "License");
17 you may not use this file except in compliance with the License.
18 You may obtain a copy of the License at
19
20 http://www.apache.org/licenses/LICENSE-2.0
21
22 Unless required by applicable law or agreed to in writing, software
23 distributed under the License is distributed on an "AS IS" BASIS,
24 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 See the License for the specific language governing permissions and
26 limitations under the License.
27 """
28 from __future__ import print_function
29
30 __author__ = u"Andr\xe9 Malo"
31
32 import re as _re
33
34 TPL = (
35 r"""
36 static const unsigned short rjsmin_charmask[128] = {
37 @@mask@@
38 };
39 """.strip()
40 + "\n"
41 )
42
43
44 def _make_charmask():
45 """Generate character mask table"""
46 # pylint: disable = too-many-branches
47
48 dull = r'[^\047"\140/\000-\040]'
49 pre_regex = r"[(,=:\[!&|?{};\r\n+*-]"
50 regex_dull = r"[^/\\\[\r\n]"
51 regex_cc_dull = r"[^\\\]\r\n]"
52
53 id_literal = r"[^\000-#%-,./:-@\[-^\140{-~-]"
54 id_literal_open = r'[^\000-\040"#%-\047)*,./:-@\\-^\140|-~]'
55 id_literal_close = r"[^\000-!#%&(*,./:-@\[\\^{|~]"
56 post_regex_off = r"[^\000-\040&)+,.:;=?\]|}-]"
57 a_z = r"[a-z]"
58
59 string_dull = r'[^\047"\140\\\r\n]'
60
61 space = r"[\000-\011\013\014\016-\040]"
62
63 charmask = []
64 for x in range(8): # pylint: disable = invalid-name
65 maskline = []
66 for y in range(16): # pylint: disable = invalid-name
67 c, mask = chr(x * 16 + y), 0
68 if _re.match(dull, c):
69 mask |= 1
70 if _re.match(pre_regex, c):
71 mask |= 2
72 if _re.match(regex_dull, c):
73 mask |= 4
74 if _re.match(regex_cc_dull, c):
75 mask |= 8
76 if _re.match(id_literal, c):
77 mask |= 16
78 if _re.match(id_literal_open, c):
79 mask |= 32
80 if _re.match(id_literal_close, c):
81 mask |= 64
82 if _re.match(string_dull, c):
83 mask |= 128
84 if _re.match(space, c):
85 mask |= 256
86 if _re.match(post_regex_off, c):
87 mask |= 512
88 if _re.match(a_z, c):
89 mask |= 1024
90
91 if mask < 10:
92 mask = " " + str(mask)
93 elif mask < 100:
94 mask = " " + str(mask)
95 elif mask < 1000:
96 mask = " " + str(mask)
97 maskline.append(str(mask))
98 if y == 7:
99 charmask.append(", ".join(maskline))
100 maskline = []
101 charmask.append(", ".join(maskline))
102 return TPL.replace("@@mask@@", ",\n ".join(charmask))
103
104
105 print(_make_charmask())