-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial RegExp #184
Initial RegExp #184
Conversation
@@ -39,6 +39,7 @@ path-absolutize = { version = "3.0", features = ["use_unix_paths_on_wasm"] } | |||
either = "1.6" | |||
levenshtein = "1" | |||
ordered-float = "4.2" | |||
regress = { version = "0.10.0", features = [] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an awesome library!
exec(input: string): RegExpExecArray | null; | ||
} | ||
|
||
interface RegExpExecArray extends Array<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man JS spec is crazy. So the returned result is an array with a bunch of added string/named properties! I think this definition where an interface extends a class works 🤞
arguments.first().unwrap().non_spread_type().expect("pattern"); | ||
let pattern_type = types.get_type_by_id(pattern_type_id); | ||
let pattern = { | ||
let Type::Constant(Constant::String(pattern)) = pattern_type else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, if the exec
is run with a constant string argument then we get a constant result.
I assume this example gets always true or false warnings under this branch (where TSC doesn't)
I wonder whether this can be extended for general (ie via Type::RootPolyType or Type::Constructor) strings not through the constant result but so that .groups
has named members. So new RegExp("Hi (?<name>.*)").exec(event.target.value)
would have groups as { name: string }. I think TS added this, but I can't find it?
I don't know whether regress
allows introspection? I don't know whether this could be a super simple scan function to pick out groups from the pattern?
If not simple then that is fine. Can merge without
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, I think this is being collected below? https://github.com/kaleidawave/ezno/pull/184/files#diff-be53d15efbd9ffdb15e107f75ef4867a569eb1ba61ecbd6cc1c468d3f49e8193R53
I will have a think about how this could work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checker/src/types/regexp.rs
Outdated
if let Some(flags) = flags { | ||
for flag in flags.chars() { | ||
match flag { | ||
'd' => unimplemented!("indices for substring matches are not supported"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not something regress
supports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regress
does not yet support all flags:
https://github.com/ridiculousfish/regress/blob/9f39399b0e61bee0602c791df8be468e00738100/src/api.rs#L59C1-L89C6
checker/src/types/regexp.rs
Outdated
for flag in flags.chars() { | ||
match flag { | ||
'd' => unimplemented!("indices for substring matches are not supported"), | ||
'g' => unimplemented!("stateful regex is not supported"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at the moment this can be ignored rather than panicking.
I think the eventful design of Ezno can support this in the future. For example evaluating a stateful RegExp could set a regexp.#used = true
property. That would be a diagnostic that I don't think any other tool does today!
checker/src/synthesis/expressions.rs
Outdated
Expression::RegexLiteral { pattern, flags: _, position: _ } => { | ||
return checking_data.types.new_regex(pattern.clone()); | ||
Expression::RegexLiteral { pattern, flags, position } => { | ||
return checking_data.types.new_regex(pattern, flags, position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice. RegExp constructor and regex literal have the same logic
Nice! Didn't expect this so soon after I wrote that issue. This is great, really impressed that you got it a nice working example. It is a great use case for Minor things that I haven't already brought up in the review
Looks great at the moment, if any of those things are too difficult LMK. Happy to just add the constant stuff as that is a really neat feature! |
I've written a constant and variable version of the I am experimenting with utf16 matching but am running into some correctness issues. I am also running into issues with optional property access of |
Awesome. If you try function greetingWho() {
const r = new RegExp("Hi (?<name>.*)")
print_type(r.exec("Hi Ben")!.groups)
} Does it print
Awesome, I think basic support is good for now. Maybe put a comment in
From last week I think property access on an or |
Hey, putting out a release this week. Would love to have this feature in! Do you think you can maybe cut it back to what was working in the screenshot? |
- Add new specification test for above - Fix clippy lints - Don't print [null] as prototype of object
Awesome!
Yep its a case of #165. The parser thinks treats
Hmm yes I think there are some problems with |
- Update regexp.rs to use crate::Map
Merged! Made a few changes before merge
I did try adding |
Fixes #183
Fixes #175