Commit Graph

41 Commits

Author SHA1 Message Date
Kodi Arfer
997321d31c Fix .end_line and .end_column of single-token models 2019-02-24 10:13:17 -05:00
Kodi Arfer
a338e4c323 Clean up a lexing test 2019-02-24 10:13:17 -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
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
097647bf6f Remove tests of cons cells 2018-04-12 16:45:17 -07:00
Simon Gomizelj
291847af15 Make HyKeyword constructor consistent
The colon is now only part of its string representation and no longer
accepted as part of the constructor:

  :foobar == HyKeyword("foobar")
2018-04-07 22:29:20 -07:00
Yigong Wang
564c030950 Raise LexException when codec can't decode some bytes 2018-04-07 11:47:06 -07:00
Kodi Arfer
52edad28e2 Overhaul mangling rules 2018-03-13 14:55:53 -04:00
Kodi Arfer
d501d4d806 Mangle symbols at compile-time instead of parse-time
This means that a HySymbol remembers its original name. That is, `a-b` and `a_b` are different symbols although `(setv a-b 1)` and `(setv a_b 1)` set the same variable (namely, `a_b`).

Most of the edits in this commit are to switch underscores to hyphens in places where mangling hasn't happened yet.

I removed some lexer tests since the lexer no longer does any mangling.
2018-03-13 14:55:15 -04:00
Simon Gomizelj
db58dacce6 Fix invalid escape sequence \s in test_escapes 2018-02-14 16:05:31 -05:00
Tuukka Turto
5c720c0110
Merge pull request #1473 from Kodiologist/new-year-2018
Update copyright years
2018-02-05 15:11:59 +02:00
Kodi Arfer
6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Kodi Arfer
a26480a81b Don't parse large floats as symbols 2017-11-11 15:14:28 -08:00
Rob Day
5a6488e353 Treat _42 etc. as a variable name, not an integer 2017-09-16 16:12:29 -07:00
Kodi Arfer
eb23ddc1e2 Add #[DELIM[ … ]DELIM] syntax for string literals 2017-09-08 11:27:34 -07:00
gilch
0f81369deb tests for #_ and (comment ...) 2017-08-04 14:35:11 -06:00
Kodi Arfer
28ce83524b Don't try to lex tag-macro calls as shebangs 2017-07-23 11:43:19 -07:00
Kodi Arfer
bb91b57dca Require capitalizing NaN and Inf like so 2017-07-10 08:50:49 -07:00
Kodi Arfer
a746ccb42c Refactor test_lex_expression_complex 2017-07-10 08:50:45 -07:00
Kodi Arfer
26d1b3f72e Don't parse 5.attr or :foo.attr as symbols 2017-06-23 08:30:37 -07:00
Kodi Arfer
c8736ebd0c Use pytest.raises in test_lex 2017-06-23 08:29:55 -07:00
gilch
6cd3201421 rename sharp macros to tag macros 2017-06-22 22:48:46 -06:00
Kodi Arfer
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer
4c38e2c9dd Rename reader macros to "sharp macros" (#1282)
They're not actually reader macros, since their arguments are parsed s-expressions, like a regular macro, not pre-parsed source text.
2017-04-21 10:07:48 -05:00
Kodi Arfer
286d568959 Fix a crash when tokenizing a single quote 2017-04-07 21:12:17 +03:00
Kodi Arfer
d649147b0c Minor test reorganization
This removes two singleton directories.
2017-02-24 12:47:35 -08:00
Paul R. Tagliamonte
b42fdc0bb7 Adding more testing. 2013-03-02 23:47:16 -05:00
Paul R. Tagliamonte
f7ff953f7e Updating states / tests for more stuff. 2013-03-02 21:08:23 -05:00
Paul R. Tagliamonte
1c238d1f4c Adding better testing. 2013-03-02 20:41:57 -05:00
Paul R. Tagliamonte
159151f847 thingthings. like licensing. 2013-03-02 20:24:32 -05:00
Paul R. Tagliamonte
627ae0ffa5 Naming the tests, etc. 2013-03-02 19:48:29 -05:00
Paul R. Tagliamonte
3a630303dc cleanup 2013-03-02 19:45:54 -05:00
Paul R. Tagliamonte
797656b1fd Add some line bits. 2013-03-02 19:41:55 -05:00
Paul R. Tagliamonte
f14ccb6d22 Adding in the Integer bits. 2013-03-02 19:28:10 -05:00
Paul R. Tagliamonte
ea326ee29b Fiddling with the lexing. 2013-03-02 18:40:00 -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