fn read_string(&mut self, opening: char) -> LexResult<Token> {
        let mut str = String::new();

        loop {
            let ch = self.read_char();

            match ch {
                // Closing string character matches that of opening
                Some(ch) if ch == opening => break,
                Some('\\') => match self.read_char() {
                    Some('\'') => str.push('\''),
                    Some('\"') => str.push('\"'),
                    Some('\\') => str.push('\\'),
                    Some('n') => str.push('\n'),
                    Some('r') => str.push('\r'),
                    Some('t') => str.push('\t'),
                    Some('0') => str.push('\0'),
                    // TODO: Allow Hex escape sequences in format \xFF

                    // TODO: I don't like repeating code like this
                    Some(ch) if ch == opening => break,
                    Some(ch) => return Err(LexError::InvalidEscape(ch)),
                    None => return Err(LexError::StringNotClosed(opening)),
                },

                // Any other character goes into the string
                Some(ch) => str.push(ch),
                None => return Err(LexError::StringNotClosed(opening)),
            }
        }

        Ok(Token::String(str))
    }
/// Read the next characters as a string
Read the next characters as a string
Read the next characters as a string
fn read_string(&mut self, opening: char) -> LexResult<Token> {
        let mut str = String::new();
        loop {
            let ch = self.read_char();
            match ch {
                // Closing string character matches that of opening
                Some(ch) if ch == opening => break,
                Some('\\') => match self.read_char() {
                    Some('\'') => str.push('\''),
                    Some('\"') => str.push('\"'),
                    Some('\\') => str.push('\\'),
                    Some('n') => str.push('\n'),
                    Some('r') => str.push('\r'),
                    Some('t') => str.push('\t'),
                    Some('0') => str.push('\0'),
                    // TODO: Allow Hex escape sequences in format \xFF
                    // TODO: I don't like repeating code like this
                    Some(ch) if ch == opening => break,
                    Some(ch) => return Err(LexError::InvalidEscape(ch)),
                    None => return Err(LexError::StringNotClosed(opening)),
                },
                // Any other character goes into the string
                Some(ch) => str.push(ch),
                None => return Err(LexError::StringNotClosed(opening)),
            }
        }
        Ok(Token::String(str))
    }
fn read_string ( & mut self , opening : char ) -> LexResult < Token > { let mut str = String :: new ( ) ; loop { let ch = self . read_char ( ) ; match ch { // Closing string character matches that of opening Some ( ch ) if ch == opening => break , Some ( '\\' ) => match self . read_char ( ) { Some ( '\'' ) => str . push ( '\'' ) , Some ( '\"' ) => str . push ( '\"' ) , Some ( '\\' ) => str . push ( '\\' ) , Some ( 'n' ) => str . push ( '\n' ) , Some ( 'r' ) => str . push ( '\r' ) , Some ( 't' ) => str . push ( '\t' ) , Some ( '0' ) => str . push ( '\0' ) , // TODO: Allow Hex escape sequences in format \xFF // TODO: I don't like repeating code like this Some ( ch ) if ch == opening => break , Some ( ch ) => return Err ( LexError :: InvalidEscape ( ch ) ) , None => return Err ( LexError :: StringNotClosed ( opening ) ) , } , // Any other character goes into the string Some ( ch ) => str . push ( ch ) , None => return Err ( LexError :: StringNotClosed ( opening ) ) , } } Ok ( Token :: String ( str ) ) }
Read the next characters as a string
Read the next characters as a string
&mut self
opening
char