Commit Graph

544 Commits

Author SHA1 Message Date
Ryan Gonzalez a964acd51d Avoid evaluating quoted f-strings
Fixes #1844.
2020-04-02 08:34:15 -04:00
Ryan Gonzalez 3c6077695b Fix some incorrect indentation 2020-04-02 08:34:15 -04:00
Kodi Arfer 80eb27906a Update copyright years 2020-01-09 14:05:12 -05:00
Kodi Arfer 0e55d7d955 Allow more than two arguments to `in` or `not-in` 2020-01-09 14:04:12 -05:00
Kodi Arfer 170febb2e8 Implement chained comparisons 2020-01-09 14:04:12 -05:00
Ryan Gonzalez 1865feb7d6 Implement PEP 3107 & 526 annotations (closes #1794) 2019-10-08 09:40:15 -05:00
Ryan Gonzalez fd8514718b Refactor function argument compilation 2019-10-08 09:40:15 -05:00
Ryan Gonzalez 6eedb19a07 Clean up assignment handling code 2019-10-08 09:40:15 -05:00
Kodi Arfer 8351ccf9d9 Allow inline Python 2019-09-17 12:04:03 -04:00
Kodi Arfer 88c0f92810 Clean up string handling in _compile_assign 2019-08-18 09:43:02 -04:00
Kodi Arfer 84fbf04f84 Fix AST representation of format strings 2019-08-13 16:07:46 -04:00
Kodi Arfer 6fb6eefd6b Make augmented assignment operators variadic 2019-08-08 15:12:03 -04:00
Kodi Arfer d32e460531 Remove some exceptions in keyword parsing 2019-07-24 11:21:11 -04:00
Ryan Gonzalez 289f172d56 Fix #1790: Rework statements in while condition
This avoids compiling them more than once while also applying some simplification.
2019-07-22 11:34:48 -04:00
Kodi Arfer d99cf80986 Run statements in the second argument of `assert`
I've edited the test to use a list instead of a set because the order of evaluation probably ought to be guaranteed.
2019-07-21 10:17:24 -04:00
Kodi Arfer 3afb4fdabe Use `mkexpr` in HyASTCompiler.imports_as_stmts 2019-07-21 10:17:24 -04:00
Kodi Arfer 349da353d6 Factor out compiler subs for constructing HyExprs 2019-07-21 10:17:24 -04:00
Kodi Arfer c99360b294 Remove support for `defclass` attribute lists 2019-07-17 14:34:31 -04:00
Kodi Arfer ba9b0239c7 Fix crashes on the new Python 3.8 alpha 2019-06-04 16:03:52 -04:00
Kodi Arfer 762e5fad2d Remove Python 2 support in hy.compiler 2019-06-04 14:01:59 -04:00
Kodi Arfer ecf0352d37 Remove aliases: `builtins`, `FileNotFoundError` 2019-06-04 14:01:59 -04:00
Kodi Arfer bba97ab2a6 Remove hy._compat's type aliases 2019-06-04 14:01:59 -04:00
Kodi Arfer 6c74cf1f07 Add `setx` for assignment expressions 2019-04-23 15:35:12 -04:00
Kodi Arfer 8df0a41d7d Provide Module(..., type_ignores) for Python 3.8 2019-04-23 15:35:12 -04:00
Kodi Arfer 0fe7f42efc Remove internal checks for Python 3.5 2019-03-17 18:28:39 -04:00
Kodi Arfer 5bfc140b4d Implement format strings 2019-02-26 14:04:24 -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 902926c543 Use ._syntax_error in place of HyTypeError.
And standardize the indentation of these calls.
2019-02-07 13:43:57 -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 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
Brandon T. Willard aa9182d76c Make the stdlib dictionary a class instance variable 2018-11-08 22:57:17 -06: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 a9fca8001e Fix AST handling of docstrings and __future__ ordering
This closes hylang/hy#1367 and closes hylang/hy#1540
2018-09-11 16:26:21 -04: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 081a710b0f Fix handling of unpacking in method calls and attribute lookups 2018-07-24 09:45:00 -07:00
Kodi Arfer 0f85331c81 Rename variables in @builds_model(HyExpression) 2018-07-24 09:41:57 -07:00
Kodi Arfer 1d2c73165d Make HyKeyword callable
Co-authored-by: Simon Gomizelj <simon@vodik.xyz>
2018-07-24 09:19:37 -07:00
Kodi Arfer 03aafad657 Make empty expressions illegal at the top level 2018-07-24 08:59:52 -07:00
Kodi Arfer af8907b151 Minor cleanup in compile_unary_operator 2018-06-30 11:04:57 -07:00
Kodi Arfer 88f33453dc Minor cleanup for `raise` and `try` 2018-06-30 11:04:11 -07:00
Kodi Arfer bd675a5db6 Unmangle in compile_expression before build_method
This ensures that e.g. the symbols "~" and "hyx_XtildeX" in the root position will both appear as "~" to the build method.
2018-06-30 11:04:11 -07:00
Kodi Arfer fca2eb93b0 Remove dead code from HyASTCompiler.compile 2018-06-30 11:04:11 -07:00
Kodi Arfer 00150c088c Remove an unused helper method in the compiler 2018-06-30 11:04:11 -07:00
Kodi Arfer e2b98effda Replace an unused variable with `_` 2018-06-30 11:04:11 -07:00
Kodi Arfer 217fc2a487 Clean up _render_quoted_form 2018-06-30 11:04:11 -07:00