Repository navigation
refactor(pattern): move the ECMA 262 regex dialect out of JsonValidator into EcmaRegex - #100
Merged
Merged
Conversation
…or into EcmaRegex Move the regex format's syntax check (isValidEcmaRegex, hasOnlyEcmaRegexSyntax), the ECMA 262 to Java translation (translatePatternToJava, translateEcmaSyntax) and the constants only they use (REGEX_UNICODE_CATEGORY, ECMA_REGEX_ESCAPES, ECMA_WHITESPACE, UNICODE_CATEGORY_NAMES) into internal object EcmaRegex in EcmaRegex.kt. DRY: the pattern keywords and the regex format share this dialect, so it belongs to neither. SRP: it changes with the differences between ECMA 262 and Java's engine, not with validation. patternCache, compiledPattern, patternMatches and matchesAnyPattern stay in JsonValidator: the cache is per-validator state (#40) and the undecided handling needs Evaluation (#32, #51). Function bodies and comments are unchanged; only visibility and qualification differ. Behaviour is unchanged, and so is the public API. Closes #95 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner
Author
Review of #100 (head
|
List matchesAnyPattern() among the pattern helpers that stay in JsonValidator, name UriSyntax.kt among the files that hold format helpers, and document EcmaRegex.translatePatternToJava, which JsonValidator now calls from another file. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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
Moves the ECMA 262 regex dialect out of
JsonValidator.ktintointernal object EcmaRegexin the newEcmaRegex.kt. This is a pure move.fun):isValidEcmaRegex(theregexformat) andtranslatePatternToJava(used bycompiledPattern)hasOnlyEcmaRegexSyntax,translateEcmaSyntaxREGEX_UNICODE_CATEGORY,ECMA_REGEX_ESCAPES,ECMA_WHITESPACE,UNICODE_CATEGORY_NAMESpatternCache,compiledPattern,patternMatchesandmatchesAnyPatternstay inJsonValidator. The cache is per-validator state (#40), and the undecided handling needsEvaluation(#32, #51).Why: DRY, because
patternand theregexformat share the dialect, and SRP, because it changes with the differences between ECMA 262 and Java's engine. Behaviour and public API are unchanged. CLAUDE.md (Architecture entry, Format Validation bullet, JsonValidator size) andmemory/MEMORY.mdare updated. There is no CHANGELOG entry.Verification
origin/master, with indentation and visibility normalised, found every moved declaration identical, KDoc and comments included. The only removed lines not found inEcmaRegex.ktare the two call sites, which are now qualified withEcmaRegex.../gradlew ktlintFormatmade no changes.CI=true ./gradlew test ktlintCheck --rerun-taskspassed, with the official suite andecmascript-regex.jsonincluded: 5,849 tests, 0 failures, 0 errors, 0 skipped (frombuild/test-results/test/*.xml).test_counts.pyexited 0 (full run 5,849, custom 1,379).JsonValidator.ktwent from 2,222 to 2,031 lines.EcmaRegex.kthas 200 lines.Closes #95
🤖 Generated with Claude Code