Optimized compilation of string patterns#540
Draft
chengluyu wants to merge 3 commits into
Draft
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
LPTK
reviewed
Jul 4, 2026
| case _: (Literal | ClassLike | Concat | CharClass) => Never | ||
| case pattern: (Record | Tuple) => pattern | ||
| case _: (MatchedClassLike | Synonym) => lastWords("unexpected specialized/complete node in specialize(lit)") | ||
LPTK
reviewed
Jul 4, 2026
| pattern Input = | ||
| ((Char.Whitespace ~ (Input as inp)) => inp) | ((c ~ (Input as inp)) => [c, ..inp]) | ("" => []) | ||
|
|
||
| :fixme |
Contributor
There was a problem hiding this comment.
This case should probably be moved out of this file.
LPTK
reviewed
Jul 4, 2026
| //│ return Stack⁰.Nil⁰ | ||
| //│ }; | ||
| //│ set tmp = [lambda⁰, lambda¹, lambda²]; | ||
| //│ set parseResult = runtime⁰.StrPat⁰.parseWhole⁰("130,1,0,3,17,47,0;37,38,43,44,45,46,47,48,58,64,65,91,95,96,97,123;0,3,1,98,-1,1,128,-1,1,129,-1,1,1,0,0,3,1,35,-1,1,65,-1,1,66,-1,1,1,3,2,1,0,4,1,44,44,1,1,5,3,2,1,15,-1,1,6,-1,2,1,9,-1,1,7,-1,2,1,10,-1,1,11,-1,1,0,8,1,97,122,1,0,8,1,65,90,2,1,13,-1,1,14,-1,1,0,9,1,97,122,1,0,9,1,65,90,1,0,12,1,46,46,2,1,17,-1,1,15,-1,3,1,18,-1,1,21,-1,1,22,-1,2,1,19,-1,1,20,-1,1,0,16,1,97,122,1,0,16,1,65,90,1,0,16,1,48,57,1,0,16,1,45,45,1,0,17,1,64,64,2,1,25,-1,1,23,-1,7,1,26,-1,1,29,-1,1,30,-1,1,31,-1,1,32,-1,1,33,-1,1,34,-1,2,1,27,-1,1,28,-1,1,0,24,1,97,122,1,0,24,1,65,90,1,0,24,1,48,57,1,0,24,1,46,46,1,0,24,1,95,95,1,0,24,1,37,37,1,0,24,1,43,43,1,0,24,1,45,45,1,1,25,4,1,1,2,5,2,1,45,-1,1,36,-1,2,1,39,-1,1,37,-1,2,1,40,-1,1,41,-1,1,0,38,1,97,122,1,0,38,1,65,90,2,1,43,-1,1,44,-1,1,0,39,1,97,122,1,0,39,1,65,90,1,0,42,1,46,46,2,1,47,-1,1,45,-1,3,1,48,-1,1,51,-1,1,52,-1,2,1,49,-1,1,50,-1,1,0,46,1,97,122,1,0,46,1,65,90,1,0,46,1,48,57,1,0,46,1,45,45,1,0,47,1,64,64,2,1,55,-1,1,53,-1,7,1,56,-1,1,59,-1,1,60,-1,1,61,-1,1,62,-1,1,63,-1,1,64,-1,2,1,57,-1,1,58,-1,1,0,54,1,97,122,1,0,54,1,65,90,1,0,54,1,48,57,1,0,54,1,46,46,1,0,54,1,95,95,1,0,54,1,37,37,1,0,54,1,43,43,1,0,54,1,45,45,1,1,55,4,1,1,2,6,1,1,3,7,1,0,67,1,44,44,1,1,68,3,2,1,78,-1,1,69,-1,2,1,72,-1,1,70,-1,2,1,73,-1,1,74,-1,1,0,71,1,97,122,1,0,71,1,65,90,2,1,76,-1,1,77,-1,1,0,72,1,97,122,1,0,72,1,65,90,1,0,75,1,46,46,2,1,80,-1,1,78,-1,3,1,81,-1,1,84,-1,1,85,-1,2,1,82,-1,1,83,-1,1,0,79,1,97,122,1,0,79,1,65,90,1,0,79,1,48,57,1,0,79,1,45,45,1,0,80,1,64,64,2,1,88,-1,1,86,-1,7,1,89,-1,1,92,-1,1,93,-1,1,94,-1,1,95,-1,1,96,-1,1,97,-1,2,1,90,-1,1,91,-1,1,0,87,1,97,122,1,0,87,1,65,90,1,0,87,1,48,57,1,0,87,1,46,46,1,0,87,1,95,95,1,0,87,1,37,37,1,0,87,1,43,43,1,0,87,1,45,45,1,1,88,4,1,1,0,5,2,1,108,-1,1,99,-1,2,1,102,-1,1,100,-1,2,1,103,-1,1,104,-1,1,0,101,1,97,122,1,0,101,1,65,90,2,1,106,-1,1,107,-1,1,0,102,1,97,122,1,0,102,1,65,90,1,0,105,1,46,46,2,1,110,-1,1,108,-1,3,1,111,-1,1,114,-1,1,115,-1,2,1,112,-1,1,113,-1,1,0,109,1,97,122,1,0,109,1,65,90,1,0,109,1,48,57,1,0,109,1,45,45,1,0,110,1,64,64,2,1,118,-1,1,116,-1,7,1,119,-1,1,122,-1,1,123,-1,1,124,-1,1,125,-1,1,126,-1,1,127,-1,2,1,120,-1,1,121,-1,1,0,117,1,97,122,1,0,117,1,65,90,1,0,117,1,48,57,1,0,117,1,46,46,1,0,117,1,95,95,1,0,117,1,37,37,1,0,117,1,43,43,1,0,117,1,45,45,1,1,118,4,1,1,0,6;8,1,7,8,4,1,3,5,0,2,0,1,4,9,1,1,0,4,1,4,0,3,1,0,8,1,4,2,3,5,1,1,2,3,5,2,0,5,6,9,1,1,0;1,1,1,1,2,1,1,1,1,1,1,3,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,6,1,1,1,1,1,1,1,1,1,1,1,1,7,1,1,1,8,1,1,1,1,1,1,1,1,1,1,1,1,7,1,1,1,8,1,1,1,1,1,1,1,1,1,1,1,1,9,1,1,1,10,1,1,1,1,1,1,1,1,1,1,1,1,9,1,1,1,10,1,1,1,1,1,1,1,11,1,1,1,1,7,1,1,1,8,1,1,1,1,1,1,1,11,1,1,1,1,7,1,1,1,8,1,1,1,1,1,1,1,12,1,1,1,1,9,1,1,1,10,1,1,1,1,1,1,1,12,1,1,1,1,9,1,1,1,10,1,1,1,1,1,1,13,1,1,14,1,1,15,1,1,1,16,1,1,1,1,1,1,17,1,1,18,1,1,19,1,1,1,20,1,1,1,1,1,1,13,1,1,14,1,21,22,1,1,1,23,1,1,1,1,1,1,13,1,1,14,1,21,22,1,1,1,23,1,1,1,1,1,1,13,1,1,14,1,21,24,1,1,1,25,1,1,1,1,1,1,13,1,1,14,1,21,24,1,1,1,25,1,1,1,1,1,1,17,1,1,18,1,26,27,1,1,1,28,1,1,1,1,1,1,17,1,1,18,1,26,27,1,1,1,28,1,1,1,1,1,1,17,1,1,18,1,26,29,1,1,1,30,1,1,1,1,1,1,17,1,1,18,1,26,29,1,1,1,30,1,1,31,1,32,1,33,34,1,35,1,1,36,1,37,1,38,1,1,1,1,1,1,13,1,1,14,1,21,22,1,1,1,23,1,1,1,1,1,1,13,1,1,14,1,21,22,1,1,1,23,1,1,1,1,1,1,13,11,1,14,1,21,24,1,1,1,25,1,1,1,1,1,1,13,11,1,14,1,21,24,1,1,1,25,1,1,39,1,40,1,41,42,1,43,1,1,44,1,45,1,46,1,1,1,1,1,1,17,1,1,18,1,26,27,1,1,1,28,1,1,1,1,1,1,17,1,1,18,1,26,27,1,1,1,28,1,1,1,1,1,1,17,12,1,18,1,26,29,1,1,1,30,1,1,1,1,1,1,17,12,1,18,1,26,29,1,1,1,30,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,31,1,32,2,33,34,1,35,1,1,36,1,37,1,38,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1,1,39,1,40,2,41,42,1,43,1,1,44,1,45,1,46,1;+AAAAA4AAAAwAAAAHAAAAEAAAAAAAAAAAAAAAAAAAAAAeAAAAAAAAADwAAAAAAAAAAAAAAANAAAAAAAAABoAAAAAAAAAA4AAAAAAAAAHAAAAADQAAAAAAAAAaAAAAAAAAAAOAAAAAAAAABwAAAAAAAAAAAAAAA2gAAAAAAAAG0AAAAAAAAADsAAAAAAAAAdgAAAANoAAAAAAAABtAAAAAAAAAA7AAAAAAAAAHYAAAAAAAAAAAAAAGBgAAAAAAAAwMAAAAYGAAAAAAAADAwAAAAAAAAAAAAAAAMIAAAAAAAABhAAAAAAAAAAxAAAAAAAAAGIAAAAAAAANDoAAAAAAABodAAAAAAAAA4PAAAAAAAAHB4AAAAAwgAAAAAAAAGEAAAAAAAAADEAAAAAAAAAYgAAAAAAAA0OgAAAAAAAGh0AAAAAAAADg8AAAAAAAAcHgAAAAAAAAAAAAAAABgAAAAAAAAAMAAAAAAAAAOgAAAAAAAAB0AAAAAAAAAA8AAAAAAAAAHgAAAAAAAANroAAAAAAABtdAAAAAAAAA7PAAAAAAAAHZ4AAAAAAYAAAAAAAAADAAAAAAAAADoAAAAAAAAAdAAAAAAAAAAPAAAAAAAAAB4AAAAAAAADa6AAAAAAAAbXQAAAAAAAAOzwAAAAAAAB2eAAAAAAABYAAAAAAADAlAAAAAAAAYElgAAAAAAAMBUAAAAAAABgKWAAAAAAAAwDQAAAAAAAGAZYAAAAAAADCFAAAAAAAAYQlgAAAAAAAMQUAAAAAAABiCWAAAAAAAA6BQAAAAAAAHQJYAAAAAAADBFAAAAAAAAYIlgAAAAAAAPAUAAAAAAAB4CWAAAwJAAAAAQAAGBIAAAABYAADAUAAAABAAAYCgAAAAFgAAMAwAAAAEAABgGAAAAAWAAAwhAAAAAQAAGEIAAAABYAADEEAAAABAAAYggAAAAFgAAOgQAAAAEAAB0CAAAAAWAAAwRAAAAAQAAGCIAAAABYAADwEAAAABAAAeAgAAAAA", tmp, input); |
Contributor
There was a problem hiding this comment.
This is a crazy scheme. It reparses a string on every match. Clearly, this should be cached into a top-level field of the current file.
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.
This PR support compiling supported string patterns into automata for whole and prefix matching. String patterns are compiled into automata encoded in string literals and the runtime can decode and execute automata. Transformations are done in the second pass after matching.