Commit Graph

2622 Commits

Author SHA1 Message Date
Kodi Arfer
6769dda4b5 Clean up NEWS 2019-02-07 14:06:58 -05:00
Kodi Arfer
e2d6640e8c
Merge pull request #1687 from brandonwillard/clean-up-exceptions
Generate more concise syntax and compiler errors
2019-02-07 14:03:24 -05:00
Kodi Arfer
96d1b9c3fa Update README 2019-02-07 13:50:30 -05:00
Brandon T. Willard
9e62903d8a Add special exception and handling for wrapper errors 2019-02-07 13:45:41 -05: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
cadfa4152b Make colored output configurable
Colored exception output is now disabled by default and configurable through
`hy.errors._hy_colored_errors` and the environment variable
`HY_COLORED_ERRORS`.

Likewise, Hy model/AST color printing is now configurable and disabled by
default.  The corresponding variables are `hy.models._hy_colored_ast_objects`
and `HY_COLORED_AST_OBJECTS`.

Closes hylang/hy#1429, closes hylang/hy#1510.
2019-02-07 13:43:58 -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
902926c543 Use ._syntax_error in place of HyTypeError.
And standardize the indentation of these calls.
2019-02-07 13:43:57 -05:00
Ryan Gonzalez
09b7f6f2df
Merge pull request #1745 from Kodiologist/update-copyright-years
Update copyright years
2019-02-07 08:30:29 -06:00
Kodi Arfer
62638b44a3 Update copyright years 2019-02-07 08:57:35 -05:00
Kodi Arfer
b9a2ab2972
Merge pull request #1736 from edouardklein/patch-1
Correct documentation of earmuff behavior
2019-02-05 13:20:52 -05:00
edouardklein
7d72e2fe74 Correct documentation of earmuff behavior
Another piece of fix #1714
2019-02-05 13:20:20 -05:00
Kodi Arfer
24a56ff15f
Merge pull request #1734 from Kodiologist/rply-077
Upgrade rply to avoid a deprecation warning
2019-02-05 13:18:27 -05:00
Kodi Arfer
d7c6fd8fa1 Upgrade rply to avoid a deprecation warning 2019-02-05 13:06:12 -05:00
Kodi Arfer
5eda96d7d3
Merge pull request #1733 from Kodiologist/py2-tokenize
Fix a Python 2 crash
2019-02-03 14:20:34 -05:00
Kodi Arfer
f1e693c96b Fix a Python 2 crash 2019-02-03 14:13:48 -05:00
Kodi Arfer
ada524e887
Merge pull request #1729 from Kodiologist/recursive-require-star
Make (require [foo [*]]) pull in macros required by `foo`
2019-01-31 13:37:52 -05:00
Kodi Arfer
983ea2dda2 Make (require [foo [*]]) pull in macros required by foo 2019-01-31 12:42:40 -05:00
Kodi Arfer
a5ed98f5b9
Merge pull request #1731 from Quelklef/master
Some documentation additions
2019-01-29 08:27:37 -05:00
Eli
e4fd74af1b Clarifying &optional documentation (fixes #1722) 2019-01-20 17:11:52 -05:00
Eli
3d2be62d4b Add synonyms for argument unpacking, for text-search purposes 2019-01-19 13:33:54 -05:00
Kodi Arfer
a42e17a025
Merge pull request #1715 from Kodiologist/interop-docs
Fix an example in interop.rst
2019-01-12 12:06:49 -05:00
Kodi Arfer
70747a58c3 Fix an example in interop.rst 2018-12-29 19:57:18 -05:00
Kodi Arfer
c4f73f061f
Merge pull request #1710 from Kodiologist/low-mangling
Fix mangling of characters below 0xFF
2018-12-29 19:56:37 -05:00
Kodi Arfer
b777972a0e Fix mangling of characters below 0xFF 2018-12-14 15:54:23 -05:00
Kodi Arfer
55ec6a0552
Merge pull request #1708 from brandonwillard/defmain-args-fix
Make `defmain` args optional or variadic when empty
2018-12-11 10:32:18 -05:00
Brandon T. Willard
f040bbe96f Update NEWS 2018-11-29 14:37:52 -06:00
Brandon T. Willard
b8b02c9df9 Handle empty defmain args
Closes hylang/hy#1707.
2018-11-29 14:37:52 -06:00
Kodi Arfer
9efd2a9d61
Merge pull request #1700 from brandonwillard/reuse-compiler-instances
Reuse Hy compiler instances
2018-11-28 19:04:41 -05:00
Brandon T. Willard
690416b3d6 Update description of eval in core.rst 2018-11-28 17:08:10 -06:00
Brandon T. Willard
3d0659b723 Update NEWS 2018-11-28 16:35:42 -06: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
Kodi Arfer
fb0220bd52
Merge pull request #1699 from brandonwillard/reorganize-imports
Reorganize utility functions and imports
2018-11-28 14:23:34 -05:00
Brandon T. Willard
8b6646d5c9 Remove hy.core compilation requirement from hy package
Previously, when importing `hy` (and any of its sub-packages/modules), Hy source
compilation for `hy.core.language` was necessarily triggered.  This, in turn,
would trigger compilation of the other standard library source files.

This commit removes that chain of events and allows the `hy` package to be
imported without any Hy compilation.

Furthermore, `read` and `read_str` are now implemented in Python and the Hy
standard library files now handle their own dependencies explicitly (i.e. they
`import` and/or `require` the other standard library files upon which they
depend).

The latter changes were necessary, because the automatically triggered
compilation of `hy.core.language` (and associated standard library files) was
serving--implicitly--as a means of producing bytecode in an order that just
happened to work for any compilation occurring afterward.  This chain of
events/dependencies was extremely cryptic, brittle, and difficult to debug, and
these changes should help to remedy that.

Closes hylang/hy#1697.
2018-11-28 14:12:33 -05: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
Kodi Arfer
3e0112f362
Merge pull request #1691 from jwilk-forks/isidentifier
Catch IndentationError in isidentifier()
2018-11-27 17:23:57 -05:00
Jakub Wilk
28504ba85d Catch IndentationError in isidentifier()
Fixes:

    >>> from hy._compat import isidentifier
    >>> isidentifier(u"  0\n 0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "hy/_compat.py", line 47, in isidentifier
        tokens = list(T.generate_tokens(StringIO(x).readline))
      File "/usr/lib/python2.7/tokenize.py", line 374, in generate_tokens
        ("<tokenize>", lnum, pos, line))
      File "<tokenize>", line 2
        0
        ^
    IndentationError: unindent does not match any outer indentation level
2018-11-27 17:15:21 -05:00
Kodi Arfer
c5abc85a2d
Merge pull request #1682 from brandonwillard/macro-changes
Macro processing updates and fixes
2018-11-09 11:13:32 -05:00
Brandon T. Willard
aa9182d76c Make the stdlib dictionary a class instance variable 2018-11-08 22:57:17 -06:00
Brandon T. Willard
3b01742818 Update NEWS 2018-11-08 22:57:17 -06:00
Brandon T. Willard
010986e8ca Implement minimal macro namespacing and add tests
This commit adds just enough namespacing to resolve a macro first in the macro's
defining module's namespace (i.e. the module assigned to the `HyASTCompiler`),
then in the namespace/module it's evaluated in.  Namespacing is accomplished by
adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be
checked for this definition namespace attribute and their car symbol resolved
per the above.

As well, a couple tests have been added that cover
- the loading of module-level macros
  - e.g. that only macros defined in the `require`d module are added
- the AST generated for `require`
  - using macros loaded from modules imported via bytecode
- the non-local macro namespace resolution described above
  - a `require`d macro that uses a macro `require` exclusively in its
    module-level namespace
- and that (second-degree `require`d) macros can reference variables within
  their module-level namespaces.

Closes hylang/hy#1268, closes hylang/hy#1650, closes hylang/hy#1416.
2018-11-08 22:57:17 -06:00
Brandon T. Willard
144a7fa240 Produce Python AST for require statements and skip self requires
Closes hylang/hy#1211.
2018-11-08 22:57:17 -06:00
Kodi Arfer
58003389c5 Integrate hy.inspect into hy.macros
It's compatibility code, and there's not a lot of it, and having a module with the same name as a standard module can be a bit troublesome.
2018-11-08 22:57:17 -06:00
Kodi Arfer
701db83ba9 Remove get_arity
This function wasn't being used anywhere.
2018-11-08 22:56:42 -06:00
Kodi Arfer
4132adb9fe
Merge pull request #1683 from brandonwillard/fix-py27-failed-import-modules
Fix `sys.modules` for failed imports in Python 2.7
2018-10-16 16:05:40 -04:00
Brandon T. Willard
a9763b34cf Fix sys.modules for failed imports in Python 2.7
Newly imported modules with compile and/or run-time errors were not being
removed from `sys.modules`.  This commit modifies the Python 2.7 loader so that
it follows Python's failed-initial-import logic and removes the module from
`sys.modules`.
2018-09-29 20:57:28 -05:00
Kodi Arfer
d2319dc91c
Merge pull request #1679 from brandonwillard/fix-doc-macro
Fix missing import in `doc` macro expansion
2018-09-24 17:01:39 -04:00
Brandon T. Willard
96f99c29d1 Fix missing import in doc macro expansion 2018-09-24 16:39:13 -04:00