Skip to content

Commit

Permalink
Remove file id argument from lexer. (#6307)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbens-starkware authored Aug 29, 2024
1 parent 01e3786 commit a75cd31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions crates/cairo-lang-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#[path = "lexer_test.rs"]
mod test;

use cairo_lang_filesystem::ids::FileId;
use cairo_lang_filesystem::span::{TextOffset, TextSpan, TextWidth};
use cairo_lang_syntax::node::ast::{
TokenNewline, TokenSingleLineComment, TokenSingleLineDocComment, TokenSingleLineInnerComment,
Expand All @@ -24,7 +23,7 @@ pub struct Lexer<'a> {

impl<'a> Lexer<'a> {
// Ctors.
pub fn from_text(db: &'a dyn SyntaxGroup, _source: FileId, text: &'a str) -> Lexer<'a> {
pub fn from_text(db: &'a dyn SyntaxGroup, text: &'a str) -> Lexer<'a> {
Lexer {
db,
text,
Expand Down
17 changes: 5 additions & 12 deletions crates/cairo-lang-parser/src/lexer_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use cairo_lang_filesystem::ids::FileId;
use cairo_lang_syntax::node::ast::{TokenSingleLineComment, TokenWhitespace};
use cairo_lang_syntax::node::kind::SyntaxKind;
use cairo_lang_syntax::node::Token;
use salsa::{InternId, InternKey};
use test_log::test;

use super::Lexer;
Expand Down Expand Up @@ -264,16 +262,12 @@ fn trivia_texts() -> Vec<&'static str> {
res
}

fn test_source() -> FileId {
FileId::from_intern_id(InternId::from(100u32))
}

#[test]
fn test_lex_single_token() {
let db_val = SimpleParserDatabase::default();
let db = &db_val;
for (kind, text) in terminal_kind_and_text() {
let mut lexer = Lexer::from_text(db, test_source(), text);
let mut lexer = Lexer::from_text(db, text);
let terminal = lexer.next().unwrap();
// TODO(spapini): Remove calling new_root on non root elements.
assert_eq!(terminal.kind, kind, "Wrong token kind, with text: \"{text}\".");
Expand All @@ -300,7 +294,7 @@ fn test_lex_double_token() {
}
for separator in separators {
let text = format!("{text0}{separator}{text1}");
let mut lexer = Lexer::from_text(db, test_source(), text.as_str());
let mut lexer = Lexer::from_text(db, text.as_str());

let terminal = lexer.next().unwrap();
let token_text = terminal.text;
Expand Down Expand Up @@ -345,7 +339,7 @@ fn test_lex_token_with_trivia() {
for leading_trivia in trivia_texts() {
for trailing_trivia in trivia_texts() {
let text = format!("{leading_trivia}{expected_token_text} {trailing_trivia}");
let mut lexer = Lexer::from_text(db, test_source(), text.as_str());
let mut lexer = Lexer::from_text(db, text.as_str());
let terminal = lexer.next().unwrap();
let token_text = terminal.text;
assert_eq!(terminal.kind, kind, "Wrong token kind, with text: \"{text}\".");
Expand All @@ -367,8 +361,7 @@ fn test_lex_token_with_trivia() {
fn test_cases() {
let db_val = SimpleParserDatabase::default();
let db = &db_val;
let res: Vec<LexerTerminal> =
Lexer::from_text(db, test_source(), "let x: &T = ` 6; // 5+ 3;").collect();
let res: Vec<LexerTerminal> = Lexer::from_text(db, "let x: &T = ` 6; // 5+ 3;").collect();
assert_eq!(
res,
vec![
Expand Down Expand Up @@ -445,7 +438,7 @@ fn test_bad_character() {
let db = &db_val;

let text = "`";
let mut lexer = Lexer::from_text(db, test_source(), text);
let mut lexer = Lexer::from_text(db, text);
let terminal = lexer.next().unwrap();
let token_text = terminal.text;
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> Parser<'a> {
file_id: FileId,
text: &'a str,
) -> SyntaxFile {
let mut lexer = Lexer::from_text(db, file_id, text);
let mut lexer = Lexer::from_text(db, text);
let next_terminal = lexer.next().unwrap();
let parser = Parser {
db,
Expand All @@ -132,7 +132,7 @@ impl<'a> Parser<'a> {
file_id: FileId,
text: &'a str,
) -> Expr {
let mut lexer = Lexer::from_text(db, file_id, text);
let mut lexer = Lexer::from_text(db, text);
let next_terminal = lexer.next().unwrap();
let mut parser = Parser {
db,
Expand Down

0 comments on commit a75cd31

Please sign in to comment.