Repository navigation
Conversation
✅ Deploy Preview for mistql canceled.
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a work-in-progress Rust implementation of MistQL, a miniature query language for JSON-like structures. The implementation provides core language features including a parser, executor, built-in functions, and type system that matches the JavaScript reference implementation's behavior.
Key changes include:
- Complete runtime type system with 8 core MistQL types (null, boolean, number, string, object, array, function, regex)
- Recursive descent parser using nom combinators that handles operator precedence and MistQL syntax
- Execution engine with context management and built-in function support
Reviewed Changes
Copilot reviewed 15 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/src/types.rs | Implements RuntimeValue enum and MistQLRegex wrapper with conversion, equality, and serialization |
| rust/src/parser.rs | Nom-based parser converting MistQL syntax to AST with proper operator precedence |
| rust/src/executor.rs | Expression execution engine with context stack management and built-in function calls |
| rust/src/builtins.rs | Comprehensive built-in function library including array, object, string, and math operations |
| rust/src/lib.rs | Main library interface providing the public query function |
| rust/src/tests.rs | Test suite loader that runs language-independent tests from shared directory |
| rust/src/lexer.rs | Lexical analyzer for tokenizing MistQL source code with position tracking |
| rust/src/instance.rs | Placeholder for future MistQL instance management (not implemented) |
| rust/src/errors.rs | Basic error type definitions using thiserror |
Comments suppressed due to low confidence (2)
rust/src/parser.rs:1
- The comment on line 371 indicates that unknown escape sequences are passed through literally. This differs from the more comprehensive Unicode handling in the nom parser version (lines 304-332). Consider consolidating escape sequence handling for consistency.
//! Parser implementation for MistQL syntax
rust/src/builtins.rs:1
- Using
fract() == 0.0to check for integers can fail for very large floating-point numbers where the fractional part cannot be represented precisely. Consider usingn.trunc() == nor checking if the number is within the valid integer range before casting.
//! Built-in functions for MistQL
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
evinism
left a comment
There was a problem hiding this comment.
Obviously this is a WIP branch, but I'm gonna go through and give my in progress thoughts anyways.
evinism
left a comment
There was a problem hiding this comment.
howdy dmitry, lots of scattered thoughts, all of which can be argued. this is killer, thank you so much.
| let mut context = Self { | ||
| stack: Vec::new(), | ||
| builtins, | ||
| root_data: data.clone(), |
There was a problem hiding this comment.
It is a little wild to have two full copies of the initial data around. Maybe there's some reorg we can do to reduce this?
We can save this for a performance pass, which I'll label as "Performance:" comments.
| let mut data = execute_expression(&stages[0], context)?; | ||
|
|
||
| for stage in &stages[1..] { | ||
| context.push_context(data.clone()); |
There was a problem hiding this comment.
Performance: Okay I'm gonna stop pointing out excessive clones because i'm realizing they're everywhere but it'd also be silly to block merge on them.
|
|
||
| impl RuntimeValue { | ||
| // Convert from serde_json::Value to RuntimeValue | ||
| pub fn from_serde_value(value: &serde_json::Value) -> Result<Self, ExecutionError> { |
There was a problem hiding this comment.
Part of me wants to separate out the serde_json translation layer from being in impl RuntimeValue.
serde_json is certainly going to be the primary way users use the rust interface, but separating it out from the main impl block into a separate trait feels right. In a perfect world, we can run and install MistQL without requiring serde_json, although that's more a vibe thing than something that I actually think people would use.
There was a problem hiding this comment.
I pulled this out into another function, it doesn't look very Rusty though. I think my challenge here is (a) I'm still new to the Rusty way of doing things, (b) I don't have good vision of what downstream usage of MistQL Rust as a client library is going to look like (almost entirely thinking about CLI usage).
| } | ||
|
|
||
| // Convert to serde_json::Value | ||
| pub fn to_serde_value(&self, permissive: bool) -> Result<serde_json::Value, ExecutionError> { |
There was a problem hiding this comment.
An interesting question is that the mistql docs mark functions and regexes as non-external types, but the query method as it is written does allow them to be passed back without filtering, and we only error on conversion to serde_json. Should we explicitly block outputting those values?
My vote would be "yes, explicitly filter them out, because it's easier from a backwards compatibility perspective." but I can be swayed. Could also imagine returning a QueryResult rather than a RuntimeValue. At that point, we can pretty much guarantee an Into<> trait rather than a TryInto<> trait for QueryResult -> serde_json::Value
There was a problem hiding this comment.
So query returns RuntimeValue, but the new cli can print both RuntimeValue (for debug purposes), which is happy to return non-extern stuff, and result.to_serde(permissive=False), which isn't (and I think that's more compatible with the other libraries' behavior?). Again, feeling like I can imagine the CLI use cases of this, but client library uses feel murky, so I don't have strong opinions on that. You might have a better sense here, in which case I'll just defer to you, otherwise we can advertise this as CLI only for now and buy some time to think through the client library requirements?
* consolidate builtin handling * consolidate contextualized expression execution among builtins * add CustomFunction support * simplify ExecutionContext builtins and custom function handling * run through clippy and lint
|
As mentioned in the tracking issue, we should add a little note to the readme saying what the rust directory is and have a link to the issue. Other than that, I'm gonna say this is good to merge. |
(Note for readers, there is a lot of private conversation around this PR not tracked on GH.)
TODO
parse_simplevalueFuture PR stuff in #70