summaryrefslogtreecommitdiff
path: root/ftt-docgen
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-06-15 13:56:38 +0300
committerLars Wirzenius <liw@liw.fi>2019-06-15 13:56:38 +0300
commit419982c48e3ba72e129fc6008f00d6873bea760b (patch)
treec9c1c0ee6742bc6a514e92503dac24fce49f89ce /ftt-docgen
parent95932ab1a2624a94d3e4c00a1ee16f5d8ed77ba8 (diff)
downloadfable-poc-419982c48e3ba72e129fc6008f00d6873bea760b.tar.gz
Fix: formatting details
Diffstat (limited to 'ftt-docgen')
-rwxr-xr-xftt-docgen18
1 files changed, 5 insertions, 13 deletions
diff --git a/ftt-docgen b/ftt-docgen
index 720bb8a..017e124 100755
--- a/ftt-docgen
+++ b/ftt-docgen
@@ -13,10 +13,10 @@ def format_keyword(line):
return '**{}** '.format(keyword) + line[len(keyword):]
def format_scenario_step(bind, line, prev_keyword):
- debug('step: line={!r} prev_keyword={}'.format(line, prev_keyword))
words = line.split()
if not words:
return line.strip(), prev_keyword
+
keyword = words[0]
real_keyword = keyword
if keyword.lower() == 'and':
@@ -24,14 +24,12 @@ def format_scenario_step(bind, line, prev_keyword):
sys.exit('AND may not be used on first step in snippet')
real_keyword = prev_keyword
line = ' '.join(words[1:])
- debug(' keyword={!r} rest={!r}'.format(keyword, line))
for b in bind:
if real_keyword not in b:
continue
m = re.match(b[real_keyword.lower()], line, re.I)
if m and m.end() == len(line):
- debug(' found binding: {!r}'.format(b))
n = len(m.groups())
if n > 0:
end = 0
@@ -43,10 +41,9 @@ def format_scenario_step(bind, line, prev_keyword):
end = m.end(i)
line = ''.join(parts) + line[m.end(n):]
line = '{} {}'.format(keyword, line)
- debug(' match: {!r}'.format(line))
break
else:
- line = '{} {}'.format(real_keyword, line)
+ line = '{} {}'.format(keyword, line)
if not line.strip():
return line
@@ -54,7 +51,6 @@ def format_scenario_step(bind, line, prev_keyword):
return format_keyword(line), real_keyword
def format_fable_snippet(bind, lines):
- debug('snippet: lines={!r}'.format(lines))
prev_keyword = None
output = []
for line in lines:
@@ -130,6 +126,8 @@ def write_listitem(bind, f, o):
for s in c.strings:
f.write('{}{}\n'.format(prepend, s))
prepend = cont
+ if o.last_line_blank:
+ f.write('\n')
return True
def write_referencedef(bind, f, o):
@@ -163,14 +161,12 @@ def walk(o, func):
walk(c, func)
def debug(msg):
- if False:
+ if True:
sys.stderr.write('DEBUG: {}\n'.format(msg))
sys.stderr.flush()
-debug('reading bindings')
bindings = yaml.safe_load(open(sys.argv[1]))
-debug('reading inputs')
text = ''.join(open(filename).read() for filename in sys.argv[2:])
start = '---\n'
@@ -181,12 +177,8 @@ if text.startswith(start):
else:
meta = ''
-debug('parse')
parser = CommonMark.DocParser()
ast = parser.parse(text)
-debug('output')
sys.stdout.write(meta)
walk(ast, lambda o: write(bindings, sys.stdout, o))
-
-debug('ok')