Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grimoire.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ programmatically on anything found here.
@include-section[(lib "resyntax/grimoire/source.scrbl")]
@include-section[(lib "resyntax/grimoire/source-group.scrbl")]
@include-section[(lib "resyntax/grimoire/syntax-path.scrbl")]
@include-section[(lib "resyntax/grimoire/string-replacement.scrbl")]
171 changes: 121 additions & 50 deletions private/string-replacement.rkt → grimoire/string-replacement.rkt

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions grimoire/string-replacement.scrbl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
resyntax/private/refactoring-result
resyntax/grimoire/source
resyntax/private/string-indent
resyntax/private/string-replacement
resyntax/grimoire/string-replacement
resyntax/private/syntax-property-bundle
resyntax/private/syntax-range
resyntax/private/syntax-replacement
Expand Down Expand Up @@ -471,7 +471,7 @@
(grouping union-into-string-replacement)
#:into into-hash))
(for ([(path replacement) (in-hash results-by-path)])
(file-apply-string-replacement! path replacement)))
(string-replacement-apply-to-file! replacement path)))


(define (substring-by-range str rng)
Expand Down
4 changes: 2 additions & 2 deletions private/line-replacement.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
rebellion/streaming/transducer
rebellion/type/record
resyntax/private/linemap
resyntax/private/string-replacement)
resyntax/grimoire/string-replacement)


(module+ test
Expand Down Expand Up @@ -72,7 +72,7 @@


(define (string-replacement->line-replacement replacement original-string)
(define new-string (string-apply-replacement original-string replacement))
(define new-string (string-replacement-apply replacement original-string))
(define orig-lmap (string-linemap original-string))
(define new-lmap (string-linemap new-string))

Expand Down
8 changes: 4 additions & 4 deletions private/refactoring-result.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
resyntax/private/linemap
resyntax/private/logger
resyntax/grimoire/source
resyntax/private/string-replacement
resyntax/grimoire/string-replacement
resyntax/private/syntax-replacement
(only-in racket/list first))

Expand Down Expand Up @@ -119,7 +119,7 @@
(mapping refactoring-result-string-replacement)
#:into union-into-string-replacement))
(define base (refactoring-result-set-base-source result-set))
(define new-contents (string-apply-replacement (source->string base) replacement))
(define new-contents (string-replacement-apply replacement (source->string base)))
(modified-source (source-original base) new-contents))


Expand Down Expand Up @@ -171,7 +171,7 @@
(define replacement
(transduce (hash-ref new-committed-replacements source '())
#:into union-into-string-replacement))
(values (source-path source) (string-apply-replacement old-contents replacement))))
(values (source-path source) (string-replacement-apply replacement old-contents))))
(define description
(refactoring-result-message (first rule-results)))
(define num-fixes (length rule-results))
Expand Down Expand Up @@ -205,7 +205,7 @@
(define start (string-replacement-start replacement))
(define original-line (linemap-position-to-line lmap (add1 start)))
(define original-column (- (add1 start) (linemap-position-to-start-of-line lmap (add1 start))))
(define refactored-source-code (string-apply-replacement full-orig-code replacement))
(define refactored-source-code (string-replacement-apply replacement full-orig-code))
(define new-code-string
(substring refactored-source-code
(string-replacement-start replacement)
Expand Down
14 changes: 7 additions & 7 deletions private/syntax-replacement.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
resyntax/private/logger
resyntax/grimoire/source
resyntax/private/string-indent
resyntax/private/string-replacement
resyntax/grimoire/string-replacement
resyntax/private/syntax-neighbors
(only-in resyntax/private/syntax-traversal syntax-search-everything)
syntax/parse
Expand Down Expand Up @@ -200,12 +200,12 @@
(+ start
(for/sum ([piece (in-list contents-with-possible-focus)]
#:break (focus? piece))
(replacement-string-span piece))))
(string-piece-span piece))))
(define focused-end
(- end
(for/sum ([piece (in-list (reverse contents-with-possible-focus))]
#:break (focus? piece))
(replacement-string-span piece))))
(string-piece-span piece))))
(define raw-contents
(append-map (λ (piece) (if (focus? piece) (focus-contents piece) (list piece)))
contents-with-possible-focus))
Expand All @@ -222,7 +222,7 @@
[else
(define normalized
(if has-focus?
(string-replacement-normalize unformatted (source->string source)
(string-replacement-focus unformatted (source->string source)
#:preserve-start focused-start
#:preserve-end focused-end)
unformatted))
Expand All @@ -244,7 +244,7 @@
;; This function is the sole integration point between Resyntax and fmt. It is used by Resyntax to
;; format any refactored code initially generated by Resyntax.
(define (string-replacement-format replacement original)
(define refactored-source-code (string-apply-replacement original replacement))
(define refactored-source-code (string-replacement-apply replacement original))
(define start (string-replacement-start replacement))
(define end (string-replacement-new-end replacement))
(define changed-code-substring (substring refactored-source-code start end))
Expand Down Expand Up @@ -347,7 +347,7 @@
;; exceed the desired line length.
(parameterize ([current-width 102])
(define formatted (string-replacement-format replacement orig-code))
(define result (string-apply-replacement orig-code formatted))
(define result (string-replacement-apply formatted orig-code))
;; The result should fit within a reasonable line length and shouldn't be multiline
(check-false (string-contains? result "\n")
"Result should remain on a single line")
Expand Down Expand Up @@ -380,7 +380,7 @@
;; Test with Racket's standard line width of 102
(parameterize ([current-width 102])
(define formatted (string-replacement-format replacement orig-line))
(define result (string-apply-replacement orig-line formatted))
(define result (string-replacement-apply formatted orig-line))

;; If the result is a single line, it should not exceed 102 characters
;; If it's multi-line, each line should not exceed 102 characters
Expand Down
2 changes: 1 addition & 1 deletion refactoring-rules.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ The Resyntax Grimoire.
Resyntax uses this information to preserve comments and formatting near the original form(s).}


@section{Narrowing the Focus of Replacements}
@section[#:tag "replacement-focusing"]{Narrowing the Focus of Replacements}

@defform[#:kind "template metafunction"
(~focus-replacement-on replacement-form)]{
Expand Down
2 changes: 1 addition & 1 deletion test/private/rackunit.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
resyntax/private/refactoring-result
resyntax/grimoire/source
resyntax/private/string-indent
resyntax/private/string-replacement
resyntax/grimoire/string-replacement
resyntax/grimoire/syntax-path
resyntax/private/syntax-property-bundle
resyntax/private/syntax-traversal
Expand Down
Loading