-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
875384f
commit be5d58e
Showing
5 changed files
with
75 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
##### | ||
# keywords.py | ||
# Translated from keywords.pl | ||
# | ||
# Extract keywords from camp.l and list them in a keywords file. These | ||
# keywords are used in autocompletion at the interactive prompt. | ||
##### | ||
|
||
import argparse | ||
import re | ||
import sys | ||
import textwrap | ||
from typing import List | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--camplfile", required=True) | ||
parser.add_argument("--output", required=True) | ||
parser.add_argument("--process-file", required=True) | ||
args = parser.parse_args() | ||
|
||
camplfile = args.camplfile | ||
output_keywords_file = args.output | ||
process_file = args.process_file | ||
|
||
# Extra keywords to add that aren't automatically extracted, currently none. | ||
extrawords: List[str] = [] | ||
|
||
with open(output_keywords_file, "w") as keywords: | ||
|
||
keywords.write( | ||
textwrap.dedent("""\ | ||
/***** | ||
* This file is automatically generated by keywords.py. | ||
* Changes will be overwritten. | ||
*****/ | ||
""" | ||
) | ||
) | ||
|
||
def add(word): | ||
keywords.write(f"ADD({word});\n") | ||
|
||
for word in extrawords: | ||
add(word) | ||
|
||
with open(camplfile) as camp: | ||
# Search for the %% separator, after which the definitions start. | ||
for line in camp: | ||
if re.search(r"^%%\s*$", line): | ||
break | ||
|
||
# Grab simple keyword definitions from camp.l | ||
for line in camp: | ||
if re.search(r"^%%\s*$", line): | ||
break # A second %% indicates the end of definitions. | ||
match = re.search(r"^([A-Za-z_][A-Za-z0-9_]*)\s*\{", line) | ||
if match: | ||
add(match.group(1)) | ||
|
||
# Grab the special commands from the interactive prompt. | ||
with open(process_file) as process: | ||
for line in process: | ||
match = re.search( | ||
r"^\s*ADDCOMMAND\(\s*([A-Za-z_][A-Za-z0-9_]*),", | ||
line, | ||
) | ||
if match: | ||
add(match.group(1)) |