OSDN Git Service

Basic system, incomplete.
[joypy/Thun.git] / implementations / Python / joy / __main__.py
1 # -*- coding: utf-8 -*-
2 #
3 #    Copyright © 2014, 2015, 2017 Simon Forman
4 #
5 #    This file is part of Thun
6 #
7 #    Thun is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (at your option) any later version.
11 #
12 #    Thun is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with Thun.  If not see <http://www.gnu.org/licenses/>.
19 #
20 import argparse, io, pkg_resources
21 from .library import initialize, inscribe, Def
22 from .joy import repl, interp
23 from .utils.pretty_print import trace
24
25
26 inscribe(trace)
27
28
29 argparser = argparse.ArgumentParser(
30     prog='thun',
31     description='Joy Interpreter',
32     )
33 argparser.add_argument(
34     '-d', '--defs',
35     action='append',
36     default=[
37         io.TextIOWrapper(
38             pkg_resources.resource_stream(__name__, 'defs.txt'),
39             encoding='UTF_8',
40             )
41         ],
42     type=argparse.FileType('r', encoding='UTF_8'),
43     help=(
44         'Add additional definition files.'
45         ' Can be used more than once.'
46         ),
47     )
48 argparser.add_argument(
49     '-q', '--quiet',
50     help='Don\'t show the prompt.',
51     default=False,
52     action='store_true',
53     )
54
55
56 args = argparser.parse_args()
57
58
59 if args.quiet:
60     j = interp
61 else:
62     j = repl
63     print('''\
64 Thun - Copyright © 2017 Simon Forman
65 This program comes with ABSOLUTELY NO WARRANTY; for details type "warranty".
66 This is free software, and you are welcome to redistribute it
67 under certain conditions; type "sharing" for details.
68 Type "words" to see a list of all words, and "[<name>] help" to print the
69 docs for a word.
70 ''')
71
72 dictionary=initialize()
73 for def_stream in args.defs:
74     Def.load_definitions(def_stream, dictionary)
75 stack = j(dictionary=dictionary)