Commit graph

57 commits

Author SHA1 Message Date
Peter Ye
08ac0d9759
Fix parsing of redirect tokens (#5322)
* Fix parsing of redirect tokens

In the parser, wrap redirect tokens such as ">", "a>", and "2>1" in a
tuple (along with the name of the redirect file, if applicable) to
differentiate them from regular command line arguments.

This ensures that a command like ![echo ">"] is parsed correctly.

We now need 2 types of IO-redirect tokens (IOREDIRECT1 and IOREDIRECT2)
so that the parser knows whether or not an IO-redirect has a file
argument. For example, "a>" has type IOREDIRECT1, whereas "2>1" has
type IOREDIRECT2.

* update ioredir tests

* add tests

* add news

* fix multiple redirections error message
2024-04-05 13:21:54 +05:30
Peter Ye
7461c507b2
Fix incorrect IOREDIRECT tokens in Python mode (#5013)
* add tests

* Fix incorrect IOREDIRECT tokens in Python mode

* add news

* Update lexer used in CompletionContextParser

The completion context lexer should start in subprocess mode so that
operators like ``2>`` are recognized as IOREDIRECT tokens.

This fixes the test case "command 2>/dev/nul{X}" for
test_completion_context.py::test_command.
2024-04-04 16:04:53 +05:30
pre-commit-ci[bot]
66c0490d37
[pre-commit.ci] pre-commit autoupdate (#5271)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-30 12:23:50 +01:00
Noortheen Raja
78091a22f3 style: isort imports
fix #4584
2022-01-31 11:16:51 -05:00
Noorhteen Raja NJ
c2d25ac251
pre-commit hook for pyupgrade (#4583)
* chore: add pyupgrade

* refactor: upgrade code to py3.7+

ran `pre-commit run pyupgrade -a` while excluding changes to ply

* fix: flake errors
2021-12-06 14:42:26 -05:00
Noorhteen Raja NJ
50a1c92004
chore: enable flake8 for tests (#4482) 2021-09-26 11:32:24 -04:00
Noorhteen Raja NJ
38295a1dd9
Remove globals (#4280)
* refactor: remove usage of global variables in abbrevs.py

* chore: add flake8-mutable to prevent mutable defaults

* fix: abbrevs expand test

* refactor: add xonsh session singleton

* refactor: fix circular errors when using xonshSession as singleton

* refactor: remove black magicked builtin attributes

* style: black format tests as well

* refactor: update tests to use xonsh-session singleton

* refactor: update abbrevs to not use builtins

* test: remove DummyCommandsCache and patch orig class

* fix: failing test_command_completers

* test: use monkeypatch to update xession fixture

* fix: failing test_pipelines

* fix: failing test_main

* chore: run test suit as single invocation

* test: fix tests/test_xonsh.xsh

* refactor: remove builtins from docs/conf.py

* fix: mypy error in jobs

* fix: test error from test_main

* test: close xession error in test_command_completers

* chore: use pytest-cov for reporting coverage

this will include subprocess calls, and will increase coverage

* style:
2021-05-20 13:14:26 +03:00
Daniel Shimon
224fc55e41
Completion context (#4017)
* completion-context: Add CompletionContextParser placeholder

Implements the xonsh (tab-)completion context parser.
This parser is meant to parse a (possibly incomplete) command line.

* completers: tools: Implement ``contextual_completer`` decorator

This is used to mark completers that want to use the parsed completion context.

* completers: Enable using contextual completers in xonsh/completer.py

* completers: readline, ptk, jupyter: Enable using contextual completers

Pass ``multiline_text`` and ``cursor_index`` to ``Completer.complete()``

* parsers: base: Refactor out a ``raise_parse_error`` function

* tokenize: Enable ``tolerant`` mode

If ``tolerant`` is True, yield ERRORTOKEN instead of
    throwing an exception when encountering an error.

* lexer: Enable ``tolerant`` mode

Tokenize without extra checks (e.g. paren matching).
When True, ERRORTOKEN contains the erroneous string instead of an error msg.

* tests: lexer: Test ``tolerant`` mode

* completion-context: Implement simple CommandContext parsing

* completion-context: tests: Test simple CommandContext parsing

* completion-context: Implement parsing sub-commands

* completion-context: tests: Test parsing sub-commands

* completion-context: Add news file

* completion-context: parser: Add parser table path to relevant locations

Code-coverage, mypy ignore list, etc.

* completion-context: Implement parsing partial strings and line continuations

* completion-context: tests: Test parsing partial strings and line continuations

* completion-context: Convert ``Span`` object to a ``slice``

* completion-context: Refactor out ``create_command`` and ``cursor_in_span``

* completion-context: Implement handling empty commands

* completion-context: tests: Test handling empty commands

* completion-context: Implement handling multiple commands

Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`

* completion-context: tests: Test handling multiple commands

Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`

* completion-context: Implement handling python context

* completion-context: tests: Test handling python context

* completers: tools: Add `contextual_command_completer`

* completers: Make `complete_skipper` contextual

* completers: Make `complete_from_man` contextual

* completers: Make `complete_from_bash` contextual and add test

* completers: Make `complete_pip` contextual and update tests

* completers: Keep opening string quote if it exists

* completion-context: Handle cursor after a closing quote

For example - cursor at the end of ``ls "/usr/"``.
1. The closing quote will be appended to all completions.
 I.e the completion ``/usr/bin`` will turn into ``/usr/bin"``
2. If not specified, lprefix will cover the closing prefix.
 I.e for ``ls "/usr/"``, the default lprefix will be 6 to include the closing quote.

* completion-context: tests: Test handling cursor after a closing quote

* completion-context: Fix bug with multiple empty commands

e.g. `;;;`

* completion-context: tests: Speed up tests

From ~15 seconds to ~500 ms

* completion-context: Expand commands and subcommands

* completion-context: Simplify `commands` rules

* completion-context: Simplify `sub_expression` rules

* completion-context: Simplify editing a multi-command token

* completion-context: Inline `create_command`

* completion-context: Implement `contextual_command_completer_for` helper

* completers: Make `complete_cd`/`complete_rmdir` contextual and add tests

* completers: path: Don't append a double-backslash in a raw string

When completing a path, if a raw string is used (e.g. `r"C:\Windows\"`),
there's no reason to append a double-backslash (e.g. `r"C:\Windows\\"`).

* completers: Make `complete_xonfig`/`complete_xontrib` contextual and add tests

* completers: Make `complete_completer` contextual and add tests

* completers: Make `complete_import` contextual and add tests

* completion-context: Add python `ctx` attribute

* completion: tools: Simplify `RichCompletion` attributes handling

* completers: Make `base`, `python`, and `commands` contextual

* Add tests
* No need for `python_mode` completer anymore

* completion: tools: Add `append_space` attribute to `RichCompletion`

* completion-context: Get all lines in a main python context

* xontrib: jedi: Make the `jedi` completer contextual

* completers: tools: Remove `get_ptk_completer` and `PromptToolkitCompleter.current_document`

These aren't needed anymore now that contextual completers can access the multiline code (via `PythonContext.multiline_code`).

* completion-context: ptk: Expand aliases

* completion-context: jupyter: Expand aliases and fix line handling

* completer: Preserve custom prefix after closing quote

* completers: bash: Ensure bash completion uses the complete prefix

* completers: pip: Append a space after a pip command

* completers: pip: Prevent bad package name completions

* completers: Remove a common prefix from `RichCompletion` if `display` wasn't provided

* completion-context: Treat cursor at edge of `&& || | ;` as normal args

This will be used for completing a space

* completers: Complete end proc keywords correctly
2021-03-30 13:37:56 -04:00
Morten Enemark Lund
044773b81c Updates to reflect that ply is only vended now 2019-02-10 14:04:05 +01:00
Gil Forsyth
8a3c8a6832 Add tests for parser and lexer for pf-strings 2018-12-25 17:40:04 -05:00
Anthony Scopatz
84a5b05a36 partial andadh fix 2018-11-07 17:32:53 -05:00
Morten Enemark Lund
9ce29f6dda Fix depration warning importing from collection 2018-10-05 11:51:31 +02:00
Anthony Scopatz
634a8ec9f2 black tests 2018-08-30 09:18:49 -05:00
Gordon Ball
d45daf97e4 Test numeric underscores in parser, lexer 2017-10-09 13:13:28 +00:00
Anthony Scopatz
1bc4920dbf lex f-strings 2017-07-16 16:13:20 -05:00
Anthony Scopatz
f9d6c8660f only issue one ws 2017-03-02 00:19:03 -05:00
Anthony Scopatz
c59b534861 lexing of line continuations in subprocs is working 2017-03-01 23:21:23 -05:00
Anthony Scopatz
cefd8d395d Require whitespace for and/or tokens in subproc mode 2017-02-26 22:42:29 -05:00
Anthony Scopatz
1b2a4a5e52 Redirection no longer require a space 2017-02-25 23:25:42 -05:00
Anthony Scopatz
4030ed8050 addes split() method to lexer 2017-02-19 20:48:26 -05:00
Gordon Ball
dbc86bc955 Support raw-string path literals 2016-12-08 13:56:45 +01:00
Gordon Ball
d6811ab29a Test different quotes rather than two identical cases 2016-10-19 15:12:24 +02:00
Gordon Ball
8de34b7b99 Add tests for path literals and backticks 2016-10-17 15:18:04 +02:00
Gil Forsyth
423d9397f5 tweaks to use subtree PLY master 2016-10-07 14:24:15 -04:00
laerus
320bb3b4da 'test_environ/lexer' 2016-07-01 12:42:07 +03:00
Konstantinos Tsakiltzidis
d4def76232 'lexer' 2016-06-22 23:12:11 +03:00
adam j hartz
638ad3a10a update tests 2016-06-16 00:59:57 -04:00
adam j hartz
2841c126df update tests, add some new tests 2016-06-16 00:59:57 -04:00
adam j hartz
6975792584 add tests for new lexer/parser changes 2016-05-21 10:29:21 -04:00
adam j hartz
d6c8dae196 test cases for updated regex glob 2016-05-19 19:23:42 -04:00
Anthony Scopatz
ef64a8001a resolved conflicts from master 2016-05-08 12:05:18 -04:00
Morten Enemark Lund
e08f3dfacf Add try-except block to ply imports 2016-05-07 21:34:19 +02:00
Morten Enemark Lund
e901b483b0 Update imports to use internal PLY 2016-05-07 11:49:11 +02:00
Anthony Scopatz
6db4b5fa3e some test fixes 2016-04-09 00:12:25 -04:00
Anthony Scopatz
0f74d164e1 double pipe token 2016-02-09 00:43:21 -05:00
Anthony Scopatz
ae509b8bb4 added annoying double ampersand token 2016-02-09 00:31:15 -05:00
Kurtis Rader
e88c863d10 Add a uniform character encoding to all files.
I wouldn't normally do something like this but issue #487 brought to
my attention the fact that too many of the python modules don't have
an encoding comment and of those that do there is a lot of pointless
inconsistency in the style of the comment.
2015-11-16 14:10:40 -08:00
Klaus Alexander Seistrup
ee65f492f2 Removed trailing whitespace 2015-07-29 23:58:25 +02:00
adam j hartz
14cb4e0de0 small ioredirect tests 2015-05-19 18:05:49 -04:00
Anthony Scopatz
ecf201bbf9 more updates 2015-04-02 19:42:38 -05:00
Anthony Scopatz
cf0c023c8e some landscape fixes 2015-04-02 19:11:50 -05:00
adam j hartz
a5ae2ca4db remove superfluous print 2015-03-24 22:32:25 -04:00
adam j hartz
7a636430a6 lexer tests 2015-03-24 22:09:50 -04:00
Anthony Scopatz
bef12986d9 test fies 2015-03-13 19:20:26 -05:00
Anthony Scopatz
7ed41791d0 some optimization fixes 2015-03-07 11:47:32 -06:00
Anthony Scopatz
1661a84ac4 all tests pass 2015-01-31 14:37:38 -06:00
Anthony Scopatz
2d2630e8a6 numeric conversions in lexer 2015-01-24 19:17:15 -06:00
Anthony Scopatz
0c1e353dad some updates 2015-01-24 00:51:08 -06:00
Anthony Scopatz
08528c1574 started parser 2015-01-24 00:17:08 -06:00
Anthony Scopatz
8e3dc90e08 added another test 2015-01-23 23:43:59 -06:00