summaryrefslogtreecommitdiff
path: root/keywords.py
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-27 14:48:26 -0500
committerpommicket <pommicket@gmail.com>2022-12-27 14:48:26 -0500
commit6912e5c194ef28d3d567ccdf0ee77f30219d9e17 (patch)
tree435ed36af14a1b833a035349d312acdb1725ff08 /keywords.py
parentc9907c20599728286e73115d11b46b169d10e1a3 (diff)
nicer keyword system
Diffstat (limited to 'keywords.py')
-rwxr-xr-xkeywords.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/keywords.py b/keywords.py
index 880cf09..6a29b25 100755
--- a/keywords.py
+++ b/keywords.py
@@ -12,19 +12,20 @@ def process_keywords(keywords):
for (type,kwd) in keywords:
c = kwd[0]
if c in keywords_by_c:
- keywords_by_c[c].append((type, kwd))
+ keywords_by_c[c].append((kwd, type))
else:
- keywords_by_c[c] = [(type, kwd)]
+ keywords_by_c[c] = [(kwd, type)]
return keywords_by_c
def output_keywords(file, keywords, language):
keywords = process_keywords(keywords)
for (c, kwds) in sorted(keywords.items()):
kwds = list(sorted(kwds))
- file.write('static Keyword const syntax_keywords_{}_{}[{}] = {{'.format(language, c, len(kwds)+1))
- file.write(','.join(map(lambda kwd: '{"'+kwd[1]+'", ' + types[kwd[0]] + '}', kwds)) + '};\n')
- file.write('static Keyword const *const syntax_all_keywords_{}[] = {{\n'.format(language))
- file.write('\t'+', '.join(["['{}'] = syntax_keywords_{}_{}".format(c, language, c) for c in sorted(keywords.keys())]) + '\n')
+ file.write('static const Keyword syntax_keywords_{}_{}[{}] = {{'.format(language, c, len(kwds)))
+ file.write(','.join(map(lambda kwd: '{"'+kwd[0]+'", ' + types[kwd[1]] + '}', kwds)) + '};\n')
+ file.write('static const KeywordList syntax_all_keywords_{}[] = {{\n'.format(language))
+ file.write('\t'+', '.join(["['{}'] = {{syntax_keywords_{}_{}, arr_count(syntax_keywords_{}_{})}}".format(
+ c, language, c, language, c) for c in sorted(keywords.keys())]) + '\n')
file.write('};\n\n')
def cant_overlap(*args):
@@ -339,9 +340,13 @@ file.write('''// keywords for all languages ted supports
// This file was auto-generated by keywords.py
''')
file.write('''typedef struct {
- char const *str;
+ const char *str;
SyntaxCharType type;
-} Keyword;\n\n''')
+} Keyword;
+typedef struct {
+ const Keyword *keywords;
+ size_t len;
+} KeywordList;\n\n''')
def label(kwds, l):
return [(l, kwd) for kwd in kwds]