refactor: Adjust again to latest 'simple' commit
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

Now with even less code!
This commit is contained in:
Glen Whitney 2021-01-15 09:44:25 -08:00
parent 5a1f9e044a
commit d0904e40cb
7 changed files with 27 additions and 46 deletions

View file

@ -41,36 +41,14 @@ is interpolated at the current location in the file currently being written.
Recursive inclusion is supported.
Note that the `{! ... !}` directive must be in lines that semiliterate would
normally copy. That is, it does not examine lines before the `start` regexp
is encountered, or after the `terminate` regexp, or between instances of
`stop` and `start`. It also doesn't check any text written from lines that
match these special expressions. Moreover, on such normally-transcribed lines,
normally copy. That is, it does not examine lines after the `terminate` regexp,
or when no mode of extraction is active. It also doesn't check any text written
from lines that match these special expressions like `start` and `stop`.
Moreover, on such normally-transcribed lines,
it's the text **after** the application of any semiliterate `replace`ments that
is checked for `{! ... !}`.
"""
def __init__(self, input_stream, output_stream, **kwargs):
""" md
### Adjusted semiliterate options
The `start` regular-expression parameter to a `semiliterate` file-inclusion
pattern is now optional. If omitted, it means that extraction begins immediately
with the first line of a file; in this case, `pause` and `terminate` retain
their usual meanings, although there is not currently any way to resume from a
`pause` when `start` is not specified. This adjustment to `semiliterate`
parameters makes it easier to extract "front-matter" style documentation from
files. It also means that a plain `{! file.md !}` directive will simply
incorporate the full contents of `file.md`.
"""
start_hot = False
if 'start' not in kwargs:
kwargs['start'] = 'dummy'
start_hot = True
super().__init__(input_stream, output_stream, **kwargs)
if start_hot:
self.extracting = True
self.start = False
include_open = re.compile(r'''(?<![`\\])(\{\!\s*)([\s'"])''')
include_quoted_file = re.compile(
r'''(['"])(?P<fn>.*?)\1\s+(?P<yml>[\s\S]*?)\s?\!\}''')
@ -138,19 +116,19 @@ disparate languages.
behavior as compared to `simple`. They are described in this section, with
default values in parentheses at the beginning of each entry.
{! plugin.py ---
{! plugin.py extract:
start: '[*]altered_config_scheme'
terminate: '^\s*\)'
replace:
- ["\\('(.*)',\\s*$", '\1\n']
- ['config_options.Type.*?default=([^\)]*)', ': (\1)']
- '^\s*#(.*\s*)$'
terminate: '^\s*\)'
!}
"""
super_sdict = dict(SimplePlugin.config_scheme)
super_semi_dflt = super_sdict['semiliterate'].default
semi_dflt = [b if r'\*' not in b['stop'] else dict(b, pattern=r'\.')
semi_dflt = [b if 'js' not in b['pattern'] else dict(b, pattern=r'\.')
for b in super_semi_dflt]
altered_config_scheme = dict(
super_sdict,