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:
parent
8b2cf00546
commit
9491348d27
1 changed files with 12 additions and 7 deletions
|
@ -22,14 +22,19 @@ import sys
|
|||
import re
|
||||
import fileinput
|
||||
|
||||
# We allow either ordered or unordered lists.
|
||||
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(
|
||||
'1\. tlvs: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?')
|
||||
'(1\.|\*) tlvs: `(?P<name>[A-Za-z0-9_]+)`( \(`?(?P<option>[^)`]*)`\))?')
|
||||
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(
|
||||
'\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.
|
||||
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)
|
||||
|
||||
# Expect a data: line before values, if any
|
||||
if line.lstrip() != '2. data:':
|
||||
if not datastartline.fullmatch(line.lstrip()):
|
||||
return _, line
|
||||
|
||||
while True:
|
||||
|
@ -131,7 +136,7 @@ def parse_tlv(genline, output, name, option):
|
|||
i, line = next(genline)
|
||||
|
||||
# Expect a types: line after tlvs.
|
||||
if line != '2. types:':
|
||||
if not tlvtypesline.fullmatch(line):
|
||||
raise ValueError('{}: Expected "2. types:" line'.format(i))
|
||||
|
||||
_, line = next(genline)
|
||||
|
@ -158,7 +163,7 @@ def parse_subtype(genline, output, name, option):
|
|||
i, line = next(genline)
|
||||
|
||||
# Expect a data: line after subtype.
|
||||
if line != '2. data:':
|
||||
if not datastartline.fullmatch(line):
|
||||
raise ValueError('{}: Expected "2. data:" line'.format(i))
|
||||
|
||||
print_csv(output, 'subtype,{}'.format(name), option)
|
||||
|
|
Loading…
Add table
Reference in a new issue