File: print_grammar.py

package info (click to toggle)
python-tatsu 5.17.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,516 kB
  • sloc: python: 13,185; makefile: 127
file content (34 lines) | stat: -rw-r--r-- 711 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright (c) 2017-2026 Juancarlo AƱez (apalala@gmail.com)
# SPDX-License-Identifier: BSD-4-Clause
from __future__ import annotations

import sys
from pathlib import Path

from rich.console import Console
from rich.syntax import Syntax


def print_grammar(filename: str):
    raw = Path(filename).read_text()

    text = "\n".join(line.rstrip() for line in raw.splitlines())

    console = Console(force_terminal=True)
    syntax = Syntax(
        text,
        "ebnf",
        theme="material",
        line_numbers=True,
        background_color="default",
    )

    console.print(syntax)


def main(args: list[str]) -> None:
    print_grammar(args[0])


if __name__ == '__main__':
    main(sys.argv[1:])