#!/usr/bin/env python3
#####
# 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 textwrap
from typing import List
with open(camplfile, encoding="utf-8") 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, encoding="utf-8") 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))