MCPcopy Create free account
hub / github.com/LaBatata101/sith-language-server / new

Method new

crates/sith_python_parser/src/lexer.rs:81–111  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 4

emptyFunction · 0.85
eat_charMethod · 0.80
to_usizeMethod · 0.80
skip_bytesMethod · 0.45

Tested by

no test coverage detected