Create a new lexer for the given input source which starts at the given offset. If the start offset is greater than 0, the cursor is moved ahead that many bytes. This means that the input source should be the complete source code and not the sliced version.
(source: &'src str, mode: Mode, start_offset: TextSize)
| 79 | /// This means that the input source should be the complete source code and not the |
| 80 | /// sliced version. |
| 81 | pub(crate) fn new(source: &'src str, mode: Mode, start_offset: TextSize) -> Self { |
| 82 | assert!( |
| 83 | u32::try_from(source.len()).is_ok(), |
| 84 | "Lexer only supports files with a size up to 4GB" |
| 85 | ); |
| 86 | |
| 87 | let mut lexer = Lexer { |
| 88 | source, |
| 89 | cursor: Cursor::new(source), |
| 90 | state: State::AfterNewline, |
| 91 | current_kind: TokenKind::EndOfFile, |
| 92 | current_range: TextRange::empty(start_offset), |
| 93 | current_value: TokenValue::None, |
| 94 | current_flags: TokenFlags::empty(), |
| 95 | nesting: 0, |
| 96 | indentations: Indentations::default(), |
| 97 | pending_indentation: None, |
| 98 | mode, |
| 99 | fstrings: FStrings::default(), |
| 100 | errors: Vec::new(), |
| 101 | }; |
| 102 | |
| 103 | if start_offset == TextSize::new(0) { |
| 104 | // TODO: Handle possible mismatch between BOM and explicit encoding declaration. |
| 105 | lexer.cursor.eat_char(BOM); |
| 106 | } else { |
| 107 | lexer.cursor.skip_bytes(start_offset.to_usize()); |
| 108 | } |
| 109 | |
| 110 | lexer |
| 111 | } |
| 112 | |
| 113 | /// Returns the kind of the current token. |
| 114 | pub(crate) fn current_kind(&self) -> TokenKind { |
nothing calls this directly
no test coverage detected