Commit Graph

84 Commits

Author SHA1 Message Date
Kodi Arfer 80eb27906a Update copyright years 2020-01-09 14:05:12 -05:00
Kodi Arfer f8d3826689
Merge pull request #1824 from refi64/drop-clint
Drop clint for colors in favor of colorama
2019-10-22 08:59:46 -04:00
Noah Snelson 7af169f089 Add HyHelper object to override builtins.help, fixes REPL prompt 2019-10-14 14:10:42 -04:00
Ryan Gonzalez 0579561b83 Drop clint for colors in favor of colorama
Closes #1820.
2019-10-08 09:50:15 -05:00
Kodi Arfer ecf0352d37 Remove aliases: `builtins`, `FileNotFoundError` 2019-06-04 14:01:59 -04:00
Kodi Arfer 2685b01a4b Remove miscellaneous PY3 checks 2019-06-04 14:01:59 -04:00
Kodi Arfer 8df0a41d7d Provide Module(..., type_ignores) for Python 3.8 2019-04-23 15:35:12 -04:00
Brandon T. Willard 4ae4baac2a Cache command line source for exceptions
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang/hy#1397.
2019-02-07 13:45:41 -05:00
Brandon T. Willard fb6feaf082 Improve correspondence with Python errors and console behavior
Compiler and command-line error messages now reflect their Python counterparts.
E.g. where Python emits a `SyntaxError`, so does Hy; same for `TypeError`s.
Multiple tests have been added that check the format and type of raised
exceptions over varying command-line invocations (e.g. interactive and not).

A new exception type for `require` errors was added so that they can be treated
like normal run-time errors and not compiler errors.

The Hy REPL has been further refactored to better match the class-structured
API.  Now, different error types are handled separately and leverage more base
class-provided functionality.

Closes hylang/hy#1486.
2019-02-07 13:45:41 -05:00
Brandon T. Willard e468d5f081 Refactor REPL error handling and filter Hy internal trace output
These changes make the Hy REPL more closely follow `code.InteractiveConsole`'s
class interface and provide minimally intrusive traceback print-out filtering
via a context manager that temporarily alters `sys.excepthook`.  In other words,
exception messages from the REPL will no longer show Hy internal
code (e.g. importer, compiler and parsing functions).

The boolean variable `hy.errors._hy_filter_internal_errors` dynamically
enables/disables trace filtering, and the env variable
`HY_FILTER_INTERNAL_ERRORS` can be used as the initial value.
2019-02-07 13:43:58 -05:00
Brandon T. Willard 51c7efe6e8 Retain compiled source and file information for exceptions
This commit refactors the exception/error classes and their handling.
It also retains Hy source strings and their originating file information, when
available, all throughout the core parser and compiler functions.

As well, with these changes, calling code is no longer responsible for providing
source and file details to exceptions,

Closes hylang/hy#657.
2019-02-07 13:43:58 -05:00
Kodi Arfer 62638b44a3 Update copyright years 2019-02-07 08:57:35 -05:00
Brandon T. Willard 15c68455ec Use a fixed compiler in `HyREPL`
These changes make `HyREPL` use a single `HyASTCompiler` instance, instead of
creating one every time a valid source string is processed.

This change avoids the unnecessary re-initiation of the standard library
`import` and `require` steps that currently occur within the module tracked by a
`HyREPL` instance.

Also, one can now pass an existing compiler instance to `hy_repl` and
`hy_compiler`.

Closes hylang/hy#1698.
2018-11-28 16:35:42 -06:00
Brandon T. Willard 86fda31ab1 Move compilation and parsing functions out of `importer.py`
Functions and variables relating to compilation and parsing have been moved to
`compiler.py` and `lex/__init__.py`, respectively.  Those functions are
  - `hy_parse` from `hy.importer` to `hy.lex`
  - `hy_eval`, `ast_compile`, and `calling_module` from `hy.importer` to
  `hy.compiler`

Closes hylang/hy#1695.
2018-11-28 14:12:33 -05:00
Brandon T. Willard 144a7fa240 Produce Python AST for `require` statements and skip self `require`s
Closes hylang/hy#1211.
2018-11-08 22:57:17 -06:00
Brandon T. Willard c0c5c9c699 Make cmdline Hy process unknown filetypes as Hy source
This change a Hy-preferring `runhy` that is used by cmdline Hy.  Standard
`runpy` is still patched so that it can run `.hy` files, but the default
behaviour for unknown filetypes is preserved (i.e. assume they are Python
source).

Closes hylang/hy#1677.
2018-09-24 16:27:50 -04:00
Brandon T. Willard cbaba4a10a Use Python cmdline file-relative sys.path
Closes hylang/hy#1457.
2018-08-26 00:27:21 -05:00
Brandon T. Willard c022abc831 Add Python cmdline bytecode option and set sys.executable
Closes hylang/hy#459.
2018-08-26 00:17:12 -05:00
Brandon T. Willard 87a5b117a1 Implement new importer using PEP-302 semantics
Python 3.x is patched in a way that integrates `.hy` source files into
Pythons default `importlib` machinery.  In Python 2.7, a PEP-302 "importer"
and "loader" is implemented according to the standard `import` logic (via
`pkgutil` and later pure-Python `imp` package code).

In both cases, the entry-point for the loaders is through `sys.path_hooks` only.
As well, the import semantics have been updated all throughout to utilize
`importlib` and follow aspects of PEP-420.  This, along with some light
patches, should allow for basic use of `runpy`, `py_compile` and `reload`.

In all cases, if a `.hy` file is shadowed by a `.py`, Hy will silently use
`.hy`.
2018-08-25 22:50:38 -05:00
Kodi Arfer 734cdcd2fd Delay importing the lexer and parser
This speeds up runs of Hy that never need to parse or compile Hy code (e.g., running a Hy program that's already byte-compiled).
2018-08-18 18:05:40 -04:00
Kodi Arfer 9368e4bc4e Use model patterns for `import` and `require`
In the process, I've banned the syntax `(import [foo])` in favor of `(import foo)`.
2018-05-20 14:07:44 -07:00
Yigong Wang be8537c0cf Add recent REPL results globals *i and most recent error *e
This comment add *1, *2, *3 as globals for recent REPL results.
*e global is also added for the most recent error object.
2018-04-02 00:21:13 -04:00
Yigong Wang 4073c78069 Add -E support for Hy REPL
This commit adds -E support for Hy. Similar to Python, hy will ignore
all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME,
that might be set.
2018-03-31 15:16:40 -07:00
Yigong Wang 57064d38dd Prettify hy command helping message 2018-03-29 23:04:22 -04:00
Kodi Arfer 3c97d2982c Use `*1` instead of `_` for REPL history
`_`, as a variable, is now the shadow subtraction operator.
2018-03-13 14:56:47 -04:00
Kodi Arfer 85968e70dd Add `mangle` and `unmangle` as core functions 2018-03-13 14:55:55 -04:00
Kodi Arfer 52edad28e2 Overhaul mangling rules 2018-03-13 14:55:53 -04:00
Kodi Arfer 6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Ryan Gonzalez e0e664c030
Merge branch 'master' into letmacro 2017-11-01 09:39:18 -05:00
gilch 6bb997dbea update astor to 0.6 2017-10-31 14:13:41 -06:00
gilch a54f6aa38b add hidden &name parameter to macros
The module name allows macros to preexpand their body in the proper
context.
2017-09-23 14:59:43 -06:00
Kodi Arfer e3e7fa8ce6 Catch exceptions raised by HyREPL.output_fn 2017-08-29 14:54:26 -07:00
Kodi Arfer 850ba03d1f Slightly simplify HyREPL 2017-07-03 17:01:12 -07:00
Kodi Arfer 2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer e478008cce Fix HyMacroExpansionError underline alignment 2017-03-24 11:09:30 -07:00
Kodi Arfer 33a696d487 Add a command-line option --repl-output-fn (especially for hy.contrib.hy-repr) 2017-03-24 09:03:12 -07:00
Kodi Arfer e4a7b317e1 Make `fn` work like `lambda` and remove `lambda` (#1228)
* with-decorator: Allow a `setv` form as the form to be decorated

This feature is of dubious value by itself, but it's necessary to allow `defn` to create a lambda instead of a `def`.

* Make `fn` work the same as `lambda`

That is, allow it to generate a `lambda` instead of a `def` statement if the function body is just an expression.

I've removed two uses of with_decorator in hy.compiler because they'd require adding another case to HyASTCompiler.compile_decorate_expression and they have no ultimate effect, anyway.

In a few tests, I've added a meaningless statement in `fn` bodies to force generation of a `def`.

I've removed `test_fn_compiler_empty_function` rather than rewrite it because it seems like a pain to maintain and not very useful.

* Remove `lambda`, now that `fn` does the same thing
2017-02-22 17:36:52 -06:00
Kodi Arfer ace125ee9b Consolidate hy.models.* and tests/models/* into one file apiece
They were a lot of similar, tiny files.
2017-02-16 19:43:00 -08:00
Jakub Wilk 7aaf5f5330 Fix invalid escape sequences
Fixes:

    hy/cmdline.py:175: DeprecationWarning: invalid escape sequence \_
    tests/lex/test_lex.py:267: DeprecationWarning: invalid escape sequence \s
    tests/compilers/test_compiler.py:45: DeprecationWarning: invalid escape sequence \*

when run against Python 3.6 with warnings enabled.
2017-01-01 00:20:04 +03:00
Kodi Arfer 397fa80380 Revert "Modernized." (#1085) (#1188)
This reverts commit 13b484ce46 and fixes #1183.
2016-12-27 09:09:58 -06:00
Elf M. Sternberg 13b484ce46 Modernized. 2016-12-20 10:54:11 +02:00
Kodi Arfer 55301884a4 Allow hy2py to use standard input instead of a file (#1163)
Fixes #1160.
2016-12-13 20:30:12 +02:00
Kodi Arfer 14fddbe6c3 Give `require` the same features as `import` (#1142)
Give `require` the same features as `import`

You can now do (require foo), (require [foo [a b c]]), (require [foo [*]]), and (require [foo :as bar]). The first and last forms get you macros named foo.a, foo.b, etc. or bar.a, bar.b, etc., respectively. The second form only gets the macros in the list.

Implements #1118 and perhaps partly addresses #277.

N.B. The new meaning of (require foo) will cause all existing code that uses macros to break. Simply replace these forms with (require [foo [*]]) to get your code working again.

There's a bit of a hack involved in the forms (require foo) or (require [foo :as bar]). When you call (foo.a ...) or (bar.a ...), Hy doesn't actually look inside modules. Instead, these (require ...) forms give the macros names that have periods in them, which happens to work fine with the way Hy finds and interprets macro calls.

* Make `require` syntax stricter and add tests

* Update documentation for `require`

* Documentation wording improvements

* Allow :as in `require` name lists
2016-11-03 09:35:58 +02:00
Kodi Arfer a33f80b2ce Allow --version as a synonym for -v
--version is a GNU standard that is also common for non-GNU programs, such as Python.
2016-09-29 09:18:04 -07:00
Andrew Scorpil 7dcc583d63 Fix issue #982: UTF-8 encode error message before passing it to clint. 2015-12-14 21:55:53 +01:00
Ryan Gonzalez d4764dcc2a Nice-ify errors with hy2py and hyc 2015-10-16 15:00:30 -05:00
Jakub Wilk 3a1af0c219 Fix typos 2015-09-29 22:57:36 +02:00
Nathan Woodrow a3ad4df6a1 Run file using hy -i
Add test for -i using file
2015-02-28 18:11:42 +10:00
Zack M. Davis 4bea6dc59e distinguish IOError when loading file from that raised by program itself
Previously, Hy scripts that raised a subclass of IOError would be caught
by code intended to deal with IOErrors raised when Hy couldn't import
the script itself, resulting in either a misleading "Can't open file"
error message, or a misleading TypeError traceback from not being able
to format the "Can't open file" message (for IOErrors for which the
errno attribute was None). This commit (a straightforward implementation
of the idea proposed by @slimetree in #714) introduces a new HyIOError
class, raises that when `import_file_to_hst` can't open the file path,
and catches it in the `cmdline_handler`.

This is believed to fix #513, #714, and #727.
2015-02-16 14:27:18 -08:00
Berker Peksag 8d6f9c3d84 Merge pull request #756 from icholy/master
Fix issues with tab completion.
2015-01-19 19:30:47 +02:00