Skip to content

refactor parser from one big file to smaller files - #18388

Merged
fdncred merged 2 commits into
nushell:mainfrom
fdncred:refactor_parser_20260610
Jun 11, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
fdncred:refactor_parser_20260610

Conversation

@fdncred

@fdncred fdncred commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR refactors parser.rs from one ~7800 line file to smaller parser_*.rs files to make it easier to consume and find things. There are no API changes. Same with the ~4400 line parse_keyword.rs file.

User-facing changes (Release notes)

N/A

Additional notes

@github-actions github-actions Bot added the A:parser Issues related to parsing label Jun 10, 2026
@fdncred
fdncred marked this pull request as draft June 10, 2026 15:57
@fdncred fdncred added category:refactor notes:hide Noted only in "Full Changelog" section labels Jun 10, 2026
@fdncred
fdncred marked this pull request as ready for review June 10, 2026 16:52
@fdncred
fdncred merged commit f70ed72 into nushell:main Jun 11, 2026
18 checks passed
@fdncred
fdncred deleted the refactor_parser_20260610 branch June 11, 2026 11:33
@github-actions github-actions Bot added this to the v0.114.0 milestone Jun 11, 2026
@cptpiepmatz cptpiepmatz added notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes and removed notes:hide Noted only in "Full Changelog" section labels Jul 4, 2026
fdncred pushed a commit that referenced this pull request Sep 10, 2026
## Description

Terminals such as macOS Terminal.app, iTerm2 and Ghostty escape spaces
with a backslash when a
file or folder is dragged into the window, for example
`/Users/mac/Downloads/a\ hourly\ list\ 1.txt`. Nushell could not accept
that text anywhere: a bare
word splits at the space, and `"a\ b"` was a parse error (`unrecognized
escape sequence '\ '`).

In this PR, I added `\ ` (a backslash followed by a space) to the escape
sequences recognized
inside double-quoted strings. It yields a literal space and joins the
existing "special" escapes
(`\(`, `\)`, `\{`, `\}`, `\$`, `\#`, `\~`, `\|`, ...), which already
cover the other characters those
terminals escape. The workflow becomes: type `"`, drop the file, type
`"`.

Why double quotes only:

- `"a\ b"` was a hard error before, so no existing script changes
meaning, on any platform.
- Single quotes and backticks stay byte-literal. The NUON spec documents
backticks as literal, and
the path completer emits raw paths inside backticks without escaping
backslashes, so giving `\ `
a meaning there would be a breaking change (and would silently rewrite
`C:\dir\ file` on Windows).
- Bare-word support is not possible without breaking Windows paths such
as `ls C:\ D:\`.

Because `unescape_string` is shared, the escape works in `"..."`,
`$"..."`, external command
arguments, `source`/`use` paths and `from nuon`. No lexer, completion or
highlighting changes were
needed. The doc comment on `unescape_string` that was lost in the parser
file split (#18388) is
restored, and the NUON spec now lists the new escape.

```nushell
"/Users/mac/Downloads/a\ hourly\ list\ 1.txt"
# => /Users/mac/Downloads/a hourly list 1.txt

ls "dir\ with\ space/file\ one.txt" | get name
# => dir with space/file one.txt

'a\ b'       # => a\ b   (unchanged)
echo `a\ b`  # => a\ b   (unchanged)
```

## User-facing changes (Release notes)

Added `\ ` (a backslash followed by a space) as an escape for a literal
space inside double-quoted
strings, so paths that terminals escape on drag-and-drop can be pasted
between double quotes
unchanged: `ls "/Users/me/My\ Documents/notes\ (1).txt"`. Previously
this was a parse error.
Single quotes, backticks and bare words are unchanged.

## Additional notes

- Closes #12464 (the double-quoted form; bare-word `\ ` remains out of
scope because of Windows
  paths, as discussed in the issue).
- Related: #11944, #18217.
- Tests added in `tests/parsing/escaping.rs`: the reporter's exact path,
interpolation, the
`\\ ` ordering, proof that single quotes and backticks stay literal, an
end-to-end `ls`/`cd` on a
directory with a space, and an external command receiving a single
argument.
- The book's list of double-quote escapes (nushell.github.io, "Working
with strings") needs the
  new entry after merge.

🤖 The test cases and this description was generated with [Claude
Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing category:refactor notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants