feat: implement mapping language lexer with full token set#43
Merged
Conversation
- Implement tokenizer for the morph mapping DSL with complete token coverage:
18 keywords (rename, select, drop, set, default, cast, as, where, sort,
each, when, not, and, or, flatten, nest, asc, desc)
- 13 operators (-> = == != > >= < <= + - * / %)
- 8 delimiters ({ } ( ) [ ] , .)
- String literals with escape sequences (\" \\ \n \t \r \uXXXX)
and direct UTF-8 support
- Number literals: integers, floats, scientific notation, negative numbers
with context-aware unary minus vs subtraction operator disambiguation
- Boolean (true/false) and null literals
- Identifiers for function names and field references
- Newlines as statement separators (collapsed)
- Line comments (# ...)
- Span tracking (line:column) for error reporting
- Add 100+ tests covering: every keyword, operator, and delimiter individually,
string escapes (quote, backslash, newline, tab, CR, unicode BMP, UTF-8),
number formats (int, float, negative, scientific, large), paths (.a.b.c,
.[0], .[*], .["key"]), comments, whitespace handling, newline collapsing,
full statements (rename, set, select, cast, sort, each blocks, function
calls), subtraction vs negative number disambiguation, error cases
(unterminated strings, invalid characters, invalid escapes, invalid numbers),
span correctness, and edge cases
Fixes #15
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.
Summary
Closes #15 — Mapping lexer.
Part of #3 (Mapping DSL epic).
Changes
Implements a complete tokenizer for the morph mapping DSL in
src/mapping/lexer.rs.Token types supported:
->===!=>>=<<=+-*/%{ } ( ) [ ] , .\"\\\\\\n\\t\\r\\uXXXX, plus direct UTF-81e10,5e-3), negative numbers with context-aware unary minus vs subtraction disambiguationtrue/false) and null literals# ...)Key design decisions:
-7is a negative integer literal when preceded by an operator/delimiter/newline, butx -7isx,Minus,7(subtraction)42.fieldtokenizes asInt(42),Dot,Ident(field)— the dot is only a decimal point if followed by a digitsetteris an identifier, notset+terTests (100+):
.a.b.c,.[0],.[*],.["key"], mixed)All checks pass:
cargo build,cargo test(361 unit + 45 integration = 406 tests),cargo fmt --check,cargo clippy -D warnings.