Skip to content
Merged
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
11 changes: 11 additions & 0 deletions crates/mq-lang/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Lexer {

/// Like [`Lexer::tokenize`], but token ranges are reported as if `input` began at `start`.
pub fn tokenize_from(&self, input: &str, module_id: ModuleId, start: Position) -> Result<Vec<Token>, SyntaxError> {
let input = input.strip_prefix('\u{FEFF}').unwrap_or(input);
let mut cursor = Cursor::new(input, module_id);
cursor.line = start.line;
cursor.col = start.column;
Expand Down Expand Up @@ -921,6 +922,16 @@ mod tests {
assert_eq!(tokens[1].range.start, Position { line: 4, column: 2 });
}

#[rstest]
#[case(Options::default())]
#[case(Options { include_spaces: true, ..Options::default() })]
fn tokenize_skips_leading_bom(#[case] options: Options) {
let lexer = Lexer::new(options);
let with_bom = lexer.tokenize("\u{FEFF}upcase()", 1.into()).unwrap();
let without_bom = lexer.tokenize("upcase()", 1.into()).unwrap();
assert_eq!(with_bom, without_bom);
}

#[rstest]
#[case("and(contains(\"test\"))",
Options::default(),
Expand Down
Loading