Skip to main content

lex

Function lex 

Source
pub fn lex<'a>(src: &'a str, file_name: &'a str) -> impl LexedSource<'a>
Expand description

Separate a source file into syntactic tokens

let file_contents = "module test_module; endmodule";
let mut tokens = lex(file_contents, "test_file.v");
assert!(matches!(tokens.next().unwrap(), (Ok(Token::Module), _)));
assert!(matches!(tokens.next().unwrap(), (Ok(Token::SimpleIdentifier("test_module")), _)));
assert!(matches!(tokens.next().unwrap(), (Ok(Token::SColon), _)));
assert!(matches!(tokens.next().unwrap(), (Ok(Token::Endmodule), _)));
assert!(tokens.next().is_none());

If the lexer encounters an error, the resulting Err(string) may contain more information if possible to discern.