Skip to content

Commit

Permalink
lexer: improve whitespace handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsippel committed Oct 1, 2023
1 parent 8fa38ca commit da89919
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/lexer.rs
Expand Up @@ -77,9 +77,10 @@ where It: Iterator<Item = char>
'>' => { self.chars.next(); return Some(Ok(LadderTypeToken::Close)); },
'~' => { self.chars.next(); return Some(Ok(LadderTypeToken::Ladder)); },
'\'' => { self.chars.next(); state = LexerState::Char(None); },
' ' => { self.chars.next(); },
c => {
if c.is_alphabetic() {
if c.is_whitespace() {
self.chars.next();
} else if c.is_alphabetic() {
state = LexerState::Sym( String::new() );
} else if c.is_digit(10) {
state = LexerState::Num( 0 );
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Expand Up @@ -121,7 +121,7 @@ impl TypeDict {
{
match self.parse_partial(tokens) {
Ok(t) => {
if let Some(tok) = tokens.peek() {
if let Some(_tok) = tokens.peek() {
Err(ParseError::UnexpectedToken)
} else {
Ok(t)
Expand Down
18 changes: 9 additions & 9 deletions src/test/lexer.rs
Expand Up @@ -83,15 +83,15 @@ fn test_lexer_app_space() {
#[test]
fn test_lexer_large() {
let mut lex = LadderTypeLexer::from(
"<Seq Date \
~<TimeSince UnixEpoch> \
~<Duration Seconds> \
~ℕ \
~<PosInt 10 BigEndian> \
~< Seq <Digit 10>~Unicode > > \
~<SepSeq Unicode ':'> \
~<Seq Unicode> \
~UTF-8 \
"<Seq Date
~<TimeSince UnixEpoch>
~<Duration Seconds>
~ℕ
~<PosInt 10 BigEndian>
~< Seq <Digit 10>~Unicode > >
~<SepSeq Unicode ':'>
~<Seq Unicode>
~UTF-8
~<Seq Byte>".chars());

assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open)));
Expand Down
18 changes: 9 additions & 9 deletions src/test/parser.rs
Expand Up @@ -134,15 +134,15 @@ fn test_parser_ladder_between() {
fn test_parser_ladder_large() {
assert_eq!(
TypeTerm::from_str(
"<Seq Date \
~<TimeSince UnixEpoch> \
~<Duration Seconds> \
~ℕ \
~<PosInt 10 BigEndian> \
~< Seq <Digit 10>~Unicode > > \
~<SepSeq Unicode ':'> \
~<Seq Unicode> \
~UTF-8 \
"<Seq Date
~<TimeSince UnixEpoch>
~<Duration Seconds>
~ℕ
~<PosInt 10 BigEndian>
~< Seq <Digit 10>~Unicode > >
~<SepSeq Unicode ':'>
~<Seq Unicode>
~UTF-8
~<Seq Byte>"),

Ok(
Expand Down

0 comments on commit da89919

Please sign in to comment.