diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-11-30 14:29:18 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-11-30 14:29:18 +0200 |
commit | 0b74a0072ac9c31ca6d375bff349bc9882f0a451 (patch) | |
tree | e80b8fe361476690e58cb8d358f1de4e19f9dc5c /blog/2019 | |
parent | 95a49d4668bafa3f197f55efc27969ca4455c5c2 (diff) | |
download | subplot.liw.fi-0b74a0072ac9c31ca6d375bff349bc9882f0a451.tar.gz |
Publish log entry
Diffstat (limited to 'blog/2019')
-rw-r--r-- | blog/2019/11/30/typesetting_scenario_steps_based_on_matched_bindings.mdwn | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/blog/2019/11/30/typesetting_scenario_steps_based_on_matched_bindings.mdwn b/blog/2019/11/30/typesetting_scenario_steps_based_on_matched_bindings.mdwn new file mode 100644 index 0000000..83e2cc6 --- /dev/null +++ b/blog/2019/11/30/typesetting_scenario_steps_based_on_matched_bindings.mdwn @@ -0,0 +1,61 @@ +[[!meta title="Typesetting scenario steps based on matched bindings"]] +[[!tag pondering]] +[[!meta date="2019-11-30 09:34"]] + +We're working on typesetting scenarios. The first iteration of this +aims at the following: + +* Subplot reads the markdown input, and a YAML file with bindings. The + YAML file is named in the markdown's metadata block (a Pandoc + extension to markdown). +* The bindings may capture parts of a step using regular expressions. +* Each scenario snippet is typeset separately. +* Each step in a snippet is typeset separately. +* There is no support for "and" or "but". The keyword must be one of + "given", "when", or "then". +* The keyword of a step is typeset in italics. +* Captured parts of a step are typeset in bold face. +* The rest of the step is typeset in a normal font. +* Steps that do not match a binding, or have an unknown keyword, or + otherwise are problematic, are typeset in monospace and have a + question mark prepended to them. A descriptive error message is + added to the document as well. + +To implement this, I'm going to want a couple of abstractions: + +* A snippet parser, as an iterator over unparsed steps (string + slices). +* A step parser, which takes an unparsed step (a string slice), and + returns a parsed step. + +A parsed step is matched against all known bindings. It can either be +a successful match, or an unsuccessful one. + +A successful match consists of a step kind (keyword), and a list of +partial steps. A partial step is either captured or uncaptured parts +of the step. + +Given a binding file like this: + +```yaml +- given: I am (?P<name>\S+) +- when: I declare myself (king|queen) +- then: everyone agrees +``` + +And a scenario snippet like this: + +``` +given I am Tomjon +when I declare myself king +then there is applause +``` + +This would result in the following parse results: + +* A matched step, with keyword _given_, an uncaptured part "I am " and + a captured part "Tomjon" +* A matched step, with keyword _when_, and an uncaptured part "I + declare myself king" +* An unmatched step, with text "then there is applause" + |