Commit Graph

27 Commits

Author SHA1 Message Date
Kodi Arfer
80eb27906a Update copyright years 2020-01-09 14:05:12 -05:00
Kodi Arfer
5dcb03b64d Move isidentifier to hy.lex 2019-06-04 14:01:59 -04:00
Kodi Arfer
7991c59480 Remove handling of UCS-2 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
56f51a9a20 Implement hy.lex.parse_one_thing 2019-02-26 13:57:50 -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
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
Kodi Arfer
b777972a0e Fix mangling of characters below 0xFF 2018-12-14 15:54:23 -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
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
6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Kodi Arfer
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer
286d568959 Fix a crash when tokenizing a single quote 2017-04-07 21:12:17 +03:00
Gregor Best
0ba620fc73 Explicitly set missing source on LexExceptions
This fixes the following code:

    (import [hy.lex [tokenize]])
    (tokenize "(foo))")
2015-07-28 16:46:26 +02:00
Bob Tolbert
f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Nicolas Dandrimont
81af09d002 Wire the rply parser
Amend the tests to account for the changes
2013-07-28 17:36:36 +02:00
Paul R. Tagliamonte
4cb4e7384e holy shit it's 2013 2013-03-18 10:27:14 -04:00
Paul R. Tagliamonte
b777ac42a7 Update etc 2013-03-02 20:38:18 -05:00
Paul R. Tagliamonte
159151f847 thingthings. like licensing. 2013-03-02 20:24:32 -05:00
Paul R. Tagliamonte
797656b1fd Add some line bits. 2013-03-02 19:41:55 -05:00
Paul R. Tagliamonte
a405b8ef52 Thinking. 2013-03-02 18:03:59 -05:00
Paul R. Tagliamonte
5c6d98a24a Rebuilding. 2013-02-28 22:37:23 -05:00
Paul R. Tagliamonte
84453e75d2 Thinking about a refacotr. 2013-02-28 22:27:20 -05:00
Paul Tagliamonte
f5836da2a5 Kill everything 2013-02-27 19:00:52 -05:00
Paul Tagliamonte
f7552149db Adding in a test lexer. 2012-12-15 16:26:03 -05:00