Пример #1
0
def _frontmatter_then_sections_OLD_WAY(lines):
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func
    scn = func(iter(lines))

    # Parse any hugo-style frontmatter
    frontmatter = None
    if scn.more and _hugo_yaml_open_and_close_frontmatter_line_rx.match(
            scn.peek):  # noqa: E501
        frontmatter = _parse_hugo_yaml_frontmatter(scn)
    yield frontmatter

    # Parse the remaining zero or more lines

    def flush():
        res = _markdown_section_via(current_markdown_header,
                                    current_section_body_lines)  # see
        current_section_body_lines.clear()
        return res

    current_markdown_header = None
    current_section_body_lines = []

    while scn.more:

        md = _markdown_header_line_probably.match(scn.peek)
        if md:
            if current_markdown_header or current_section_body_lines:
                yield flush()
            current_markdown_header = _markdown_header_via_matchdata(md)
            scn.advance()
        else:
            current_section_body_lines.append(scn.next())

    if current_markdown_header or current_section_body_lines:
        yield flush()
Пример #2
0
def parse_help_screen(lines):
    lines = _dont_trust_lines(lines)
    func = _treelib().sections_via_lines_allow_align_right__
    sections = func(lines)
    sect_via_lines = _build_section_parser()
    sections = tuple(sect_via_lines(lines) for lines in sections)
    return _help_screen(sections)
Пример #3
0
def _parse_interstitials(interstitial_lines, iden_via, throwing_listener):
    if not any('\n' != s for s in interstitial_lines):
        return
    from ._directives import func
    kv = func(interstitial_lines, iden_via, throwing_listener)
    one = kv.pop('our_range', None)
    two = kv.pop('put_new_issues_in_this_range', None)
    assert not kv
    return two or one
Пример #4
0
 def output_lineser():
     scn = func(iter(lines))
     first_line = scn.next()  # ..
     # If the component only produced one line, make it look like this
     if scn.empty:
         yield ''.join((ss.tab, k, ': ', first_line))
     else:
         yield ''.join((ss.tab, k, ' ', first_line))
     while scn.more:
         yield ''.join((ss.tab, scn.next()))
Пример #5
0
 def determine_rootie():
     from ._common import open_git_subprocess_ as func
     itr = func(('rev-parse', '--show-toplevel'), cwd=coll_path)
     proc = next(itr)
     k, v = next(itr)
     assert 'sout' == k
     k, _ = next(itr)
     assert 'done' == k
     proc.terminate()
     assert 0 == proc.returncode
     return v[:-1]
Пример #6
0
def _do_build_option_index(lines):
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func
    scn = func(lines)
    while True:
        o = _parse_option_line(scn.next())
        additional_desc_lines = []
        while scn.more and _regex.match(r'^[ ]+[^- ]', scn.peek):
            additional_desc_lines.append(scn.next())
        o.additional_desc_lines_NOT_USED = tuple(additional_desc_lines)  # meh
        yield o.main_long_switch, o
        if scn.empty:
            break
Пример #7
0
    def we_have_latest_SHA_in_the_singleton_table():

        any_stop_SHA = singleton_text.get(_last_indexed_SHA_key)

        func = git_log_numstat
        itr = func(coll_path, any_stop_SHA, ('git', 'log', '--numstat'))
        next(itr)  # #HERE1 we don't hold on to the proc

        # If real HEAD was the stop HEAD, scanner is empty
        scn = _scanner_via_iterator(itr)
        if scn.empty:
            return True

        self.scn = scn
        return False
Пример #8
0
def _execute_terminal_command(comp, k, rest, ss, listener):

    if 'show' == k:
        assert not rest
        return _execute_show(comp, ss, listener)

    if 'list' == k:
        assert not rest
        listener('output', 'expression', lambda: _to_splay_lines(comp))
        return 0

    for kk, func in _to_additional_commands(comp):
        if k != kk:
            continue
        kw = {}
        kw.update(command_name=k, rest=rest)
        kw.update(stylesheet=ss, listener=listener)
        return func(kw)

    return _bad_command_or_component(comp, listener, 'command', k)
Пример #9
0
def _do_crazy_hack(doc):
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func
    scn = func(normal_lines_via_docstring(doc))

    # Cache up lines that don't look like this one line
    these_lines = []
    while 'Args:\n' != scn.peek:  # (doing it dirty for now
        these_lines.append(scn.next())
    scn.advance()

    yield tuple(these_lines)

    # Parse every item of the Args section
    import re
    da = re.DOTALL
    rx_one = re.compile('^[ ]{4}([a-zA-Z][a-zA-Z_0-9]*):[ ]+([^ ].*)', da)
    rx_two = re.compile('^[ ]{5}[ ]*(?P<rest>[^ ].*)', da)

    md = rx_one.match(scn.peek)
    if not md:
        xx(f"Item line? {scn.peek!r}")
    scn.advance()

    # Parse each arg while dealing with its any multiple descrciption lines
    while True:
        param_identifier, desc_line_1 = md.groups()
        desc_lines = [desc_line_1]
        while scn.more and (md := rx_two.match(scn.peek)):
            desc_lines.append(md['rest'])
            scn.advance()
        yield param_identifier, tuple(desc_lines)
        if scn.empty:
            break
        if (md := rx_one.match(scn.peek)):
            scn.advance()
            continue
Пример #10
0
def _execute_show_for_component(k, c, ss, listener):
    c = _proxy_if_necessary(c)

    lines = []
    from . import capture_output_lines_ as func
    rc = _execute_show(c, ss, func(lines.append, listener))
    assert isinstance(rc, int)  # #todo
    if rc:
        return rc
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func

    def output_lineser():
        scn = func(iter(lines))
        first_line = scn.next()  # ..
        # If the component only produced one line, make it look like this
        if scn.empty:
            yield ''.join((ss.tab, k, ': ', first_line))
        else:
            yield ''.join((ss.tab, k, ' ', first_line))
        while scn.more:
            yield ''.join((ss.tab, scn.next()))

    listener('output', 'expression', output_lineser)
    return 0
Пример #11
0
def _scanner_via_iterator(itr):
    assert hasattr(itr, '__next__')
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func
    return func(itr)
Пример #12
0
def _issues_collection_via(x, listener, opn=None):
    from pho._issues import issues_collection_via_ as func
    return func(x, listener, opn)
Пример #13
0
    def traverse_whole_collection():
        last_iden_tagged_as_hole = None
        last_iden_with_real_major_hole_above_it = None
        last_iden_with_real_minor_hole_above_it = None
        above_iden, branch, ent = eg_iden, False, None

        from text_lib.magnetics.scanner_via import \
            scanner_via_iterator as func
        scn = func(ents)

        # If using a limiter range, advance past the ceiling limit
        # (ceiling is physically above floor in the file, and comes first,
        # because lower line numbers have higher identifier numbers)

        while scn.more and is_over_limiter_ceiling(scn.peek.identifier):
            scn.advance()

        while scn.more:

            ent = scn.peek
            iden = ent.identifier

            # If using a limiter range, stop when you hit the floor limit
            if is_under_limiter_floor(iden):
                break

            if tagged_as_hole(ent):
                last_iden_tagged_as_hole = iden
            was_under_branch = branch
            jump_distance, branch = compare(above_iden, iden, branch)

            if jump_distance < 0:
                reason = f"{above_iden.to_string()} then {iden.to_string()}"
                xx(reason)

            assert -1 < jump_distance

            if 0 == jump_distance:
                # The header node at the bottom of a bunch of compound issues
                assert was_under_branch and not branch
            elif 1 == jump_distance:
                pass  # normal tight lyfe
            else:
                assert 0 < jump_distance
                # simple to simple (so was not): major hole
                # compound to compound (so was): minor hole
                # simple to compound (so was not): major hole
                # compound to simple (so was): major hole

                ok = True
                yes1 = not numerals_not_let
                yes2 = iden.has_sub_component and 14 == iden.minor_integer
                if yes1 and yes2:
                    # YIKES if you're about to say that 14 (aka "N") has a
                    # minor hole above it AND you're doing letters not numerals
                    # then don't say it, because that would be 15 (aka "O")
                    # and we don't use that letter because it looks like "0".
                    # Take this check out and see that this "false hole"
                    # exists everywhere in our collections.

                    def lines():
                        yield "(won't use 'O' because it looks like '0')"

                    listener('info', 'expression', 'skipping_O', lines)

                    ok = False

                if was_under_branch and branch:
                    if ok:
                        last_iden_with_real_minor_hole_above_it = iden
                elif branch:  # new at writing. experiment.
                    # begining of the world to compound: minor hole
                    if ok:
                        last_iden_with_real_minor_hole_above_it = iden
                else:
                    last_iden_with_real_major_hole_above_it = iden
            above_iden = iden
            scn.advance()

        if (iden := last_iden_tagged_as_hole):
            return 'last_iden_tagged_as_hole', iden
Пример #14
0
def _scanner_via_iterator(itr):
    from text_lib.magnetics.scanner_via import scanner_via_iterator as func
    return func(itr)