Skip to content

Commit aebfe44

Browse files
committed
Add simple detection of formal languages used in draft, partially
based on the code in getauthors by Jari Arkko - Legacy-Id: 12657
1 parent 6378594 commit aebfe44

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

ietf/utils/draft.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,28 @@ def get_wordcount(self):
301301
count += sum(1 for _ in word_re.finditer(l))
302302
return count
303303

304+
# ------------------------------------------------------------------
305+
def get_formal_languages(self):
306+
language_regexps = [
307+
("abnf", [re.compile(r"\bABNF"), re.compile(r" +[a-zA-Z][a-zA-Z0-9_-]* +=[/ ]")]),
308+
("asn1", [re.compile(r'DEFINITIONS +::= +BEGIN')]),
309+
("cbor", [re.compile(r'\b(?:CBOR|CDDL)\b'), re.compile(r" +[a-zA-Z][a-zA-Z0-9_-]* += +[\{\[\(]")]),
310+
("ccode", [re.compile(r"(?:\+\+\))|(?:for \(i)|(?: [!=]= 0\) \{)|(?: struct [a-zA-Z_0-9]+ \{)")]),
311+
("json", [re.compile(r'\bJSON\b'), re.compile(r" \"[^\"]+\" ?: [a-zA-Z0-9\.\"\{\[]")]),
312+
("xml", [re.compile(r"<\?xml")]),
313+
]
314+
already_matched = set()
315+
for l in self.lines:
316+
for lang_name, patterns in language_regexps:
317+
for p in patterns:
318+
if p not in already_matched and p.search(l):
319+
already_matched.add(p)
320+
return [
321+
lang_name
322+
for lang_name, patterns in language_regexps
323+
if all(p in already_matched for p in patterns)
324+
]
325+
304326
# ----------------------------------------------------------------------
305327
def get_status(self):
306328
if self._status == None:

0 commit comments

Comments
 (0)