Skip to content

Refactor Lexer to be infallible for LSP support#1428

Merged
KCarretto merged 6 commits intomainfrom
eldritch-lexer-refactor-11738474779397551328
Dec 28, 2025
Merged

Refactor Lexer to be infallible for LSP support#1428
KCarretto merged 6 commits intomainfrom
eldritch-lexer-refactor-11738474779397551328

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

Refactored the Lexer in eldritch-core to return Vec<Token> directly, ensuring it never panics or returns Err on syntax errors. This allows tools (like an LSP) to obtain a partial token stream even when the code is incomplete or contains errors. Syntax errors are now captured as TokenKind::Error tokens. The Interpreter was updated to handle these error tokens gracefully.


PR created automatically by Jules for task 11738474779397551328 started by @KCarretto

- Changed `Lexer::scan_tokens` to return `Vec<Token>` instead of `Result`.
- Added `TokenKind::Error` to represent syntax errors (e.g., unterminated strings, invalid chars) without aborting the token stream.
- Updated `Interpreter::interpret` to check for `TokenKind::Error` and return early errors, preserving runtime behavior.
- Updated `Interpreter::complete` to ignore error tokens, allowing autocompletion to work on partially invalid code.
- Updated tests to match the new infallible Lexer API.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 27, 2025

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
2735    ±0 2735    ±0 0    ±0 0    ±0 0    ±0 0    ±0 1ms    ±0

Previous Results

Build 🏗️ Result 🧪 Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
#73 2735 2735 0 0 0 0 27.0s

Insights

Average Tests per Run Total Flaky Tests Total Failed Slowest Test (p95)
2735 0 0 46.8s

Slowest Tests

Test 📝 Results 📊 Duration (avg) ⏱️ Duration (p95) ⏱️
eldritch: random::string_impl::tests::test_string_uniform 3 41.2s 46.8s
eldritch: random::string_impl::tests::test_string_uniform 3 41.2s 46.8s
eldritch: random::string_impl::tests::test_string_uniform 3 41.2s 46.8s
eldritch: pivot::port_scan_impl::tests::test_portscan_return_type_starlark_dict_from_interpreter 3 3.0s 8.9s
eldritch: pivot::port_scan_impl::tests::test_portscan_return_type_starlark_dict_from_interpreter 3 3.0s 8.9s
eldritch: pivot::port_scan_impl::tests::test_portscan_return_type_starlark_dict_from_interpreter 3 3.0s 8.9s
eldritch: pivot::ssh_copy_impl::tests::test_pivot_ssh_copy 3 4.3s 8.8s
eldritch: pivot::ssh_copy_impl::tests::test_pivot_ssh_copy 3 4.3s 8.8s
eldritch: pivot::ssh_copy_impl::tests::test_pivot_ssh_copy 3 4.3s 8.8s
eldritch: pivot::ssh_exec_impl::tests::test_pivot_ssh_exec 3 4.3s 8.8s

🎉 No failed tests in this run. | 🍂 No flaky tests in this run.

Github Test Reporter by CTRF 💚

🔄 This comment has been updated

@KCarretto
Copy link
Copy Markdown
Collaborator

Jules run cargo fmt

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

Jules run cargo fmt

Running cargo fmt now.

KCarretto and others added 4 commits December 27, 2025 18:12
- Updated `eldritch-core/src/token.rs` to handle `TokenKind::Error` in `fmt::Display`.
- Updated `eldritch-repl/src/core.rs` to handle `Vec<Token>` return type from `Lexer::scan_tokens` and correctly process error tokens for REPL logic.
- Verified that all tests pass in `implants/`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@KCarretto KCarretto marked this pull request as ready for review December 28, 2025 00:31
@KCarretto KCarretto requested review from Cictrone and hulto December 28, 2025 00:31
@KCarretto KCarretto merged commit 1e79794 into main Dec 28, 2025
7 checks passed
@KCarretto KCarretto deleted the eldritch-lexer-refactor-11738474779397551328 branch December 28, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants