Draft
Conversation
Co-authored-by: lxcid <297156+lxcid@users.noreply.github.com>
- Made tokens optional in all AST node types (TextNode, Scheme, Authority, Query, Fragment, UriAst) - Parser still populates tokens when parsing from strings (backward compatible) - Allows easy handcrafting of AST without providing token arrays - Added comprehensive tests for handcrafting AST without tokens - Updated validation function to handle optional tokens - All existing tests pass Co-authored-by: lxcid <297156+lxcid@users.noreply.github.com>
Added documentation showing how tokens are optional and how to easily handcraft AST without tokens Co-authored-by: lxcid <297156+lxcid@users.noreply.github.com>
Removed unnecessary validation for empty tokens array since empty arrays are valid (e.g., for empty input) Co-authored-by: lxcid <297156+lxcid@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Make token optional in AST to improve developer experience
Make tokens optional in AST for handcrafting
Jan 24, 2026
Changed field names to improve clarity and maintain lossless tokenization: - Scheme.colon -> Scheme.colonToken (optional) - Query.delimiter -> Query.delimiterToken (optional) - Fragment.delimiter -> Fragment.delimiterToken (optional) This makes the intent clear that these fields store token data while keeping them optional for handcrafting. All tests updated and passing. Co-authored-by: lxcid <297156+lxcid@users.noreply.github.com>
Author
Done! Renamed fields to use "Token" suffix for clarity:
All fields remain optional for handcrafting while maintaining lossless tokenization when parsing. Changes in commit 279fabd. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handcrafting AST nodes required providing token arrays and position metadata even when not needed, creating unnecessary boilerplate.
Changes
Type system: Made
tokensfield optional inTextNode,Scheme,Authority,Query,Fragment, andUriAst. Renamed delimiter/colon token fields with "Token" suffix for clarity (colon→colonToken,delimiter→delimiterToken) and made them optional.Parser: Uses nullish coalescing to handle optional tokens. Still populates all token fields when parsing from strings (backward compatible, lossless tokenization maintained).
Validation: Removed token presence checks to support handcrafted AST.
Tests: Added 17 tests covering handcrafted AST creation and stringification. Updated all existing tests to use new field names.
Documentation: Added handcrafting examples to README.
Field Naming
The "Token" suffix makes it clear these fields store token data (not just semantic information), enabling true lossless tokenization while keeping fields optional for handcrafting:
Scheme.colonToken(optional) - stores the ':' tokenQuery.delimiterToken(optional) - stores the '?' tokenFragment.delimiterToken(optional) - stores the '#' tokenExample
Before:
After:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.