lexer: Consume invalid characters
This commit is contained in:
parent
32bde2f749
commit
5c4c8bcb80
@ -46,7 +46,7 @@ fn lex_tokens(file: &str, path: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{e:?}");
|
println!("{e:?}");
|
||||||
break;
|
continue;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if let Some(path) = path {
|
if let Some(path) = path {
|
||||||
|
@ -45,7 +45,7 @@ pub mod lexer_iter {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```rust
|
/// ```rust
|
||||||
///# use conlang::lexer::Lexer;
|
/// # use conlang::lexer::Lexer;
|
||||||
/// // Read in your code from somewhere
|
/// // Read in your code from somewhere
|
||||||
/// let some_code = "
|
/// let some_code = "
|
||||||
/// fn main () {
|
/// fn main () {
|
||||||
@ -59,7 +59,7 @@ pub mod lexer_iter {
|
|||||||
/// println!("{first_token:?}");
|
/// println!("{first_token:?}");
|
||||||
/// // Loop over all the rest of the tokens
|
/// // Loop over all the rest of the tokens
|
||||||
/// for token in lexer {
|
/// for token in lexer {
|
||||||
///# let token: Result<_,()> = Ok(token.unwrap());
|
/// # let token: Result<_,()> = Ok(token.unwrap());
|
||||||
/// match token {
|
/// match token {
|
||||||
/// Ok(token) => println!("{token:?}"),
|
/// Ok(token) => println!("{token:?}"),
|
||||||
/// Err(e) => eprintln!("{e:?}"),
|
/// Err(e) => eprintln!("{e:?}"),
|
||||||
@ -123,7 +123,11 @@ impl<'t> Lexer<'t> {
|
|||||||
'\'' => self.consume()?.character(),
|
'\'' => self.consume()?.character(),
|
||||||
'_' => self.identifier(),
|
'_' => self.identifier(),
|
||||||
i if i.is_xid_start() => self.identifier(),
|
i if i.is_xid_start() => self.identifier(),
|
||||||
e => Err(Error::unexpected_char(e, self.line(), self.col())),
|
e => {
|
||||||
|
let err = Err(Error::unexpected_char(e, self.line(), self.col()));
|
||||||
|
let _ = self.consume();
|
||||||
|
err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Returns the current line
|
/// Returns the current line
|
||||||
|
Loading…
Reference in New Issue
Block a user