Skip to content

Commit 2045d0b

Browse files
committed
fixed more coercion issues
1 parent d12284b commit 2045d0b

File tree

7 files changed

+869
-50
lines changed

7 files changed

+869
-50
lines changed

docs/src/content/docs/self-hosting-demo.mdx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,37 @@ import Quote from '../../components/Quote.astro';
1414
In computer programming, self-hosting is the use of a program as part of the toolchain or operating
1515
system that produces new versions of that same program—for example, a compiler that can compile
1616
its own source code.
17-
</Quote>
17+
</Quote>
1818

19-
Watch Refaktor rename the entire project to `awesome_file_renaming_tool`, run the test suite
20-
using it's new name, and then use the new binary to change itself back again:
19+
Refaktor is capable of "self-hosting". It can rename the entire project to `awesome_file_renaming_tool`,
20+
run the entire test suite, and then use the newly compiled binary to rename itself back again:
2121

2222
```bash
2323
# Clone and build
2424
git clone https://github.com/DocSpring/refaktor
2525
cd refaktor
26-
cargo build --release
26+
cargo build
2727

2828
# Use refaktor to rename itself to awesome_file_renaming_tool
29-
./target/release/refaktor rename refaktor awesome_file_renaming_tool --preview table --yes
29+
./target/debug/refaktor rename refaktor awesome_file_renaming_tool --preview table --yes
3030

31-
# Remove the old binary, run tests, and rebuild with the new name
31+
# Make sure the old compiled binary is gone
3232
rm -rf target
33+
34+
# Run the full test suite
3335
cargo test
34-
cargo build --release
3536

36-
# Now use the new renamed binary to rename itself back to refaktor
37-
./target/release/awesome_file_renaming_tool rename awesome_file_renaming_tool refaktor --preview table --yes
37+
# Build the "awesome_file_renaming_tool" binary
38+
cargo build
39+
40+
# Use the new binary to rename itself back to refaktor
41+
./target/debug/awesome_file_renaming_tool rename awesome_file_renaming_tool refaktor --preview table --yes
3842

39-
# Back to the original
43+
# Back to the original name
4044
rm -rf target
4145
cargo test
42-
cargo build --release
43-
./target/release/refaktor --help
46+
cargo build
47+
./target/debug/refaktor --help
4448

4549
git status
4650
# On branch main

refaktor-core/src/scanner.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,28 +474,56 @@ fn extract_immediate_context(line: &str, match_start: usize, match_end: usize) -
474474
let mut context_end = char_end;
475475

476476
// Characters that are part of identifiers or compound names
477-
let is_identifier_char =
478-
|c: char| -> bool { c.is_alphanumeric() || c == '_' || c == '-' || c == '.' };
479-
480-
// Characters that indicate we should stop extending context but might be part of a path/namespace
481-
let is_path_separator = |c: char| -> bool { c == '/' || c == '\\' || c == ':' || c == '@' };
477+
let is_identifier_char = |c: char| -> bool { c.is_alphanumeric() || c == '_' || c == '-' };
478+
479+
// Characters that act as separators - we should NOT extend past these
480+
// This includes: /, \, :, @, ., [, ], (, ), {, }, =, quotes, spaces
481+
let is_separator = |c: char| -> bool {
482+
matches!(
483+
c,
484+
'/' | '\\'
485+
| ':'
486+
| '@'
487+
| '.'
488+
| '['
489+
| ']'
490+
| '('
491+
| ')'
492+
| '{'
493+
| '}'
494+
| '='
495+
| '"'
496+
| '\''
497+
| '`'
498+
| ' '
499+
| '\t'
500+
| '\n'
501+
| '\r'
502+
| ','
503+
| ';'
504+
)
505+
};
482506

483-
// Extend backwards to find the start of the identifier/path chain
507+
// Extend backwards to find the start of the immediate identifier
508+
// Stop at any separator character
484509
while context_start > 0 {
485510
let prev_char = chars[context_start - 1];
486-
if is_identifier_char(prev_char) || is_path_separator(prev_char) {
511+
if is_identifier_char(prev_char) {
487512
context_start -= 1;
488513
} else {
514+
// Stop at any separator or other character
489515
break;
490516
}
491517
}
492518

493-
// Extend forwards to find the end of the identifier/path chain
519+
// Extend forwards to find the end of the immediate identifier
520+
// Stop at any separator character
494521
while context_end < chars.len() {
495522
let next_char = chars[context_end];
496-
if is_identifier_char(next_char) || is_path_separator(next_char) {
523+
if is_identifier_char(next_char) {
497524
context_end += 1;
498525
} else {
526+
// Stop at any separator or other character
499527
break;
500528
}
501529
}

0 commit comments

Comments
 (0)