You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful if there was a built-in bump_line() fn that would bump the lexer to the next line. A more generic bump_terminator(pat: P) could be useful too. I know there are several ways to achieve this behavior, but I feel like it would be a nice ergonomic fn to have.
EDIT: Proof of Concept
pubtraitLexerExtensions{fnbump_terminator(&mutself,pat:&[char]);//pub fn bump_terminator(&mut self, pat: P);fnbump_line(&mutself);}impl<'a,T>LexerExtensionsfor logos::Lexer<'a,T>whereT: logos::Logos<'a,Source = str>{fnbump_line(&mutself){ifletSome(next) = self.remainder().lines().next(){self.bump(next.len() + 1);}}fnbump_terminator(&mutself,pat:&[char]){ifletSome(next) = self.remainder().split_terminator(pat).next(){self.bump(next.len() + 1);}}}#[test]fntest_lexer_extensions(){use logos::Logos;#[derive(Logos)]enumTest{#[token("A")]A,#[token("B")]B,#[token("C")]C}letmut lex = Test::lexer(r" Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ");
lex.bump_line();assert_eq!(lex.remainder(),r" LoremIpsumissimplydummytextoftheprintingandtypesetting industry.LoremIpsumhasbeentheindustry's standarddummytexteversincethe1500s, whenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimen book. Ithassurvivednotonlyfivecenturies, butalsotheleapintoelectronictypesetting, remainingessentially unchanged. Itwaspopularisedinthe1960swiththereleaseofLetrasetsheetscontainingLoremIpsumpassages, andmorerecentlywithdesktoppublishingsoftwarelikeAldusPageMakerincludingversionsofLoremIpsum. ");
lex.bump_terminator(&[',']);assert_eq!(lex.remainder(),r" whenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimen book. Ithassurvivednotonlyfivecenturies, butalsotheleapintoelectronictypesetting, remainingessentially unchanged. Itwaspopularisedinthe1960swiththereleaseofLetrasetsheetscontainingLoremIpsumpassages, andmorerecentlywithdesktoppublishingsoftwarelikeAldusPageMakerincludingversionsofLoremIpsum. ");}
The text was updated successfully, but these errors were encountered:
It would be useful if there was a built-in
bump_line()
fn that would bump the lexer to the next line. A more genericbump_terminator(pat: P)
could be useful too. I know there are several ways to achieve this behavior, but I feel like it would be a nice ergonomic fn to have.EDIT: Proof of Concept
The text was updated successfully, but these errors were encountered: