-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow initializing lexers with a char iterator (#42)
This fixes #41 in an almost backwards compatible way. Generated lexers now have an extra constructor: impl<I: Iterator<Item = char> + Clone> Lexer<'static, I> { fn new_from_iter(iter: I) -> Self { Lexer(::lexgen_util::Lexer::new_from_iter(iter)) } } API of the generated lexers are exactly the same, however, if a lexer is constructed with `new_from_iter` instead of `new` or `new_with_state`, then `match_` method will panic in runtime. This is because in lexers constructed with `new_from_iter` we don't have the input string, so cannot return a slice to it. Instead use `match_loc` to get the start and end locations of the current match. Only breaking change is the generated types now have one more generic argument, for the iterator type. So for a lexer like: lexer! { MyLexer -> MyToken; ... } Instead of struct MyLexer<'input>(...); we now generate struct MyLexer<'input, I: Iterator<Item = char> + Clone>(...); So any code that refers to the lexer type will break. Other than this the changes should be backwards compatible. Fixes #41
- Loading branch information
Showing
6 changed files
with
192 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters