Load defs from files into dictionary.
This commit is contained in:
parent
31cd926ab4
commit
aa0b01fdcc
|
|
@ -18,7 +18,7 @@
|
|||
# along with Thun. If not see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse, io, pkg_resources
|
||||
from .library import initialize, inscribe
|
||||
from .library import initialize, inscribe, Def
|
||||
from .joy import repl, interp
|
||||
from .utils.pretty_print import trace
|
||||
|
||||
|
|
@ -68,4 +68,8 @@ under certain conditions; type "sharing" for details.
|
|||
Type "words" to see a list of all words, and "[<name>] help" to print the
|
||||
docs for a word.
|
||||
''')
|
||||
stack = j(dictionary=initialize())
|
||||
|
||||
dictionary=initialize()
|
||||
for def_stream in args.defs:
|
||||
Def.load_definitions(def_stream, dictionary)
|
||||
stack = j(dictionary=dictionary)
|
||||
|
|
|
|||
|
|
@ -323,6 +323,14 @@ class Def(DefinitionWrapper):
|
|||
self.__doc__ = expression_to_string(body)
|
||||
self._compiled = None
|
||||
|
||||
@classmethod
|
||||
def load_definitions(class_, stream, dictionary):
|
||||
for line in stream:
|
||||
if line.lstrip().startswith('#'):
|
||||
continue
|
||||
name, body = text_to_expression(line)
|
||||
inscribe(class_(name, body), dictionary)
|
||||
|
||||
|
||||
def _text_to_defs(text):
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue