コード例 #1
0
ファイル: aboutapp.py プロジェクト: webbsimax/openvario-shell
 async def _update_version(
         self, wdg: urwid.Text, fetcher: Coroutine[None, None,
                                                   Optional[str]]) -> None:
     ver = await fetcher
     if ver is not None:
         wdg.set_text(("success message", ver))
     else:
         wdg.set_text("N/A")
コード例 #2
0
ファイル: lark_shell.py プロジェクト: ThatXliner/lark_shell
def _parse(grammar: str, parse_input: str, output_obj: urwid.Text,
           chosen_parser: str) -> None:
    """Update the UI with the given grammar and input."""
    try:
        # Create a parser with `chosen_parser`
        parser = lark.Lark(grammar, parser=chosen_parser, lexer="auto")

        # Generate a tree
        tree = parser.parse(parse_input)

    # Parsing errors
    except (lark.exceptions.GrammarError, TypeError) as e:
        output_obj.set_text(("error", f"Incomplete grammar!\n{str(e)}"))
    except lark.exceptions.ParseError as e:
        output_obj.set_text(("error", str(e)))
    except lark.exceptions.UnexpectedInput as e:
        output_obj.set_text(("error", str(e.get_context(parse_input))))

    # Importing errors
    except FileNotFoundError:  # The relative imported file was not found
        output_obj.set_text(
            ("error", "File not found, did you spell it correctly?"))
    except KeyError as e:
        _ = e.args[0]  # The token
        # pylint: disable=E1101
        output_obj.set_text(
            ("error", f"Could not import {_.type.lower()} '{_.value}'"))
    except lark.exceptions.LarkError as e:  # Everything else
        output_obj.set_text(("error", repr(e)))

    else:  # Parsing succeeded
        output_obj.set_text(("success", str(tree.pretty())))