1
0
Fork 0
mirror of https://github.com/lightning/bolts.git synced 2025-03-09 15:52:43 +01:00

tools/extract-formats.py: allow '*' as well as '1.'/'2.'

The format for TLV types looked pretty, but @ZmnSCPxj points out that
successive ordered lists in markdown get merged into one megalist.

If we allow ordered or unordered lists, we're a bit more futureproof
against formatting changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-07-26 19:09:33 +09:30
parent 8b2cf00546
commit 9491348d27

View file

@ -22,14 +22,19 @@ import sys
import re import re
import fileinput import fileinput
# We allow either ordered or unordered lists.
typeline = re.compile( typeline = re.compile(
'1\. type: (?P<value>[-0-9A-Za-z_|]+) \(`(?P<name>[A-Za-z0-9_]+)`\)( \(`?(?P<option>[^)`]*)`\))?') '(1\.|\*) type: (?P<value>[-0-9A-Za-z_|]+) \(`(?P<name>[A-Za-z0-9_]+)`\)( \(`?(?P<option>[^)`]*)`\))?')
tlvline = re.compile( tlvline = re.compile(
'1\. tlvs: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?') '(1\.|\*) tlvs: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?')
subtypeline = re.compile( subtypeline = re.compile(
'1\. subtype: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?') '(1\.|\*) subtype: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?')
dataline = re.compile( dataline = re.compile(
'\s+\* \[`(?P<typefield>[-_a-zA-Z0-9*+]+)`:`(?P<name>[_a-z0-9]+)`\]( \(`?(?P<option>[^)`]*)`?\))?') '\s+([0-9]+\.|\*) \[`(?P<typefield>[-_a-zA-Z0-9*+]+)`:`(?P<name>[_a-z0-9]+)`\]( \(`?(?P<option>[^)`]*)`?\))?')
datastartline = re.compile(
'(2\.|\*) data:')
tlvtypesline = re.compile(
'(2\.|\*) types:')
# Generator to give us one line at a time. # Generator to give us one line at a time.
def next_line(args, lines): def next_line(args, lines):
@ -96,7 +101,7 @@ def parse_type(genline, output, name, value, option, in_tlv=None):
print_csv(output, '{},{},{}'.format(type_prefix, name, value), option) print_csv(output, '{},{},{}'.format(type_prefix, name, value), option)
# Expect a data: line before values, if any # Expect a data: line before values, if any
if line.lstrip() != '2. data:': if not datastartline.fullmatch(line.lstrip()):
return _, line return _, line
while True: while True:
@ -131,7 +136,7 @@ def parse_tlv(genline, output, name, option):
i, line = next(genline) i, line = next(genline)
# Expect a types: line after tlvs. # Expect a types: line after tlvs.
if line != '2. types:': if not tlvtypesline.fullmatch(line):
raise ValueError('{}: Expected "2. types:" line'.format(i)) raise ValueError('{}: Expected "2. types:" line'.format(i))
_, line = next(genline) _, line = next(genline)
@ -158,7 +163,7 @@ def parse_subtype(genline, output, name, option):
i, line = next(genline) i, line = next(genline)
# Expect a data: line after subtype. # Expect a data: line after subtype.
if line != '2. data:': if not datastartline.fullmatch(line):
raise ValueError('{}: Expected "2. data:" line'.format(i)) raise ValueError('{}: Expected "2. data:" line'.format(i))
print_csv(output, 'subtype,{}'.format(name), option) print_csv(output, 'subtype,{}'.format(name), option)