Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_json_parser): Clippy & Unicode table generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Nov 21, 2022
1 parent eab845d commit 83d8b95
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
* text=auto eol=lf
crates/rome_js_parser/src/lexer/tables.rs linguist-generated=true text=auto eol=lf
crates/rome_js_unicode_table/src/tables.rs linguist-generated=true text=auto eol=lf
**/generated/* linguist-generated=true text=auto eol=lf
crates/rome_js_analyze/src/analyzers.rs linguist-generated=true text=auto eol=lf
crates/rome_js_analyze/src/assists.rs linguist-generated=true text=auto eol=lf
Expand Down
39 changes: 31 additions & 8 deletions crates/rome_js_unicode_table/src/tables.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions crates/rome_json_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,24 +510,23 @@ impl<'src> Lexer<'src> {
self.advance(1);
}

Some(_) => match state {
LexStringState::InString => {
Some(_) => {
if matches!(state, LexStringState::InString) {
let c = self.current_char_unchecked();
self.diagnostics.push(
ParseDiagnostic::new(
self.file_id,
"Invalid escape sequence",
escape_start..self.text_position() + (c as char).text_len(),
)
.hint(r#"Valid escape sequences are: `\\`, `\/`, `/"`, `\b\`, `\f`, `\n`, `\r`, `\t` or any unicode escape sequence `\uXXXX` where X is hexedecimal number. "#),
.hint(r#"Valid escape sequences are: `\\`, `\/`, `/"`, `\b\`, `\f`, `\n`, `\r`, `\t` or any unicode escape sequence `\uXXXX` where X is hexedecimal number. "#),
);
state = LexStringState::InvalidEscapeSequence;
}
_ => {}
},
}

None => match state {
LexStringState::InString => {
None => {
if matches!(state, LexStringState::InString) {
self.diagnostics.push(ParseDiagnostic::new(
self.file_id,
"Expected an escape sequence following a backslash, but found none",
Expand All @@ -537,8 +536,7 @@ impl<'src> Lexer<'src> {
);
state = LexStringState::InvalidEscapeSequence;
}
_ => {}
},
}
}
}
WHS if matches!(chr, b'\n' | b'\r') => {
Expand Down Expand Up @@ -615,11 +613,12 @@ impl<'src> Lexer<'src> {
self.assert_byte(b'u');
self.assert_at_char_boundary();

let start = self
.text_position()
let start = self.text_position();

let start = start
// Subtract 1 to get position of `\`
.checked_sub(TextSize::from(1))
.unwrap_or(self.text_position());
.unwrap_or(start);

self.advance(1); // Advance over `u'`

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_json_parser/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome:
for diagnostic in diagnostics {
let error = diagnostic
.clone()
.with_file_path(&file_name)
.with_file_path(file_name)
.with_file_source_code(&content);

formatter
Expand Down
2 changes: 1 addition & 1 deletion xtask/codegen/src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use quote::quote;

mod paths {
pub const DERIVED_CORE_PROPERTIES: &str = "target/DerivedCoreProperties.txt";
pub const TABLES: &str = "crates/rome_js_parser/src/lexer/tables.rs";
pub const TABLES: &str = "crates/rome_js_unicode_table/src/tables.rs";
}

pub fn generate_tables() -> Result<()> {
Expand Down

0 comments on commit 83d8b95

Please sign in to comment.